Implemented simple octopus-based num_monitors_online() query.
authorSimon Gerber <simon.gerber@inf.ethz.ch>
Wed, 26 Nov 2014 17:41:32 +0000 (18:41 +0100)
committerSimon Gerber <simon.gerber@inf.ethz.ch>
Wed, 26 Nov 2014 17:46:55 +0000 (18:46 +0100)
usr/monitor/Hakefile
usr/monitor/capops/capsend.c
usr/monitor/capops/init.c
usr/monitor/capops/internal.c [new file with mode: 0644]
usr/monitor/capops/internal.h
usr/monitor/capops/revoke.c
usr/monitor/include/monitor.h

index 14e0963..9d8d9f2 100644 (file)
@@ -35,7 +35,7 @@
                      "capops/caplock.c", "capops/copy.c", "capops/move.c",
                      "capops/retrieve.c", "capops/delete.c", "capops/revoke.c",
                      "capops/retype.c", "capops/init.c", "capops/magic.c",
-                     "capops/deletestep.c" ]
+                     "capops/deletestep.c", "capops/internal.c" ]
 
      arch_srcs "x86_32"  = [ "arch/x86/boot.c", "arch/x86/inter.c", "arch/x86/monitor_server.c", "arch/x86/notify_ipi.c" ]
      arch_srcs "x86_64"  = [ "arch/x86/boot.c", "arch/x86/inter.c", "arch/x86/monitor_server.c", "arch/x86/notify_ipi.c" ]
index 63f3dd5..0072329 100644 (file)
@@ -159,13 +159,10 @@ bool capsend_handle_mc_reply(struct capsend_mc_st *st)
 static errval_t
 capsend_broadcast(struct capsend_mc_st *bc_st, struct capability *cap, capsend_send_fn send_cont)
 {
-    if (num_monitors == -1) {
-        USER_PANIC_ERR(ERR_NOTIMP,
-                "do not have number of online monitors, cannot do broadcast");
-    }
     errval_t err;
+    size_t online_monitors = num_monitors_online();
     // do not count self when calculating #dest cores
-    int dest_count = num_monitors - 1;
+    int dest_count = online_monitors - 1;
     DEBUG_CAPOPS("%s: dest_count = %d\n", __FUNCTION__, dest_count);
     DEBUG_CAPOPS("%s: num_queued = %d\n", __FUNCTION__, bc_st->num_queued);
     DEBUG_CAPOPS("%s: num_pending = %d\n", __FUNCTION__, bc_st->num_pending);
index 62f781c..4a00d6b 100644 (file)
@@ -4,10 +4,6 @@
 #include "internal.h"
 #include "delete_int.h"
 
-// XXX: to make merge compile, capsend_broadcast() will obviously not work
-// right now!
-int num_monitors = -1;
-
 errval_t capops_init(struct waitset *ws, struct intermon_binding *b)
 {
     DEBUG_CAPOPS("%s\n", __FUNCTION__);
diff --git a/usr/monitor/capops/internal.c b/usr/monitor/capops/internal.c
new file mode 100644 (file)
index 0000000..d48e1aa
--- /dev/null
@@ -0,0 +1,43 @@
+// for num_spawnds_online()
+#include <if/octopus_rpcclient_defs.h>
+#include <octopus/getset.h> // for oct_read TODO
+#include <octopus/trigger.h> // for NOP_TRIGGER
+#include "internal.h"
+
+size_t num_monitors_online(void)
+{
+    errval_t err;
+    struct octopus_rpc_client *r = get_octopus_rpc_client();
+    if (r == NULL) {
+        return LIB_ERR_NAMESERVICE_NOT_BOUND;
+    }
+
+    char* buffer = NULL;
+    errval_t error_code;
+    octopus_trigger_id_t tid;
+
+    char** names = NULL;
+    size_t count = 0;
+
+    static char* spawnds = "r'spawn.[0-9]+' { iref: _ }";
+        err = r->vtbl.get_names(r, spawnds, NOP_TRIGGER, &buffer, &tid, &error_code);
+    if (err_is_fail(err) || err_is_fail(error_code)) {
+        err = err_push(err, SPAWN_ERR_FIND_SPAWNDS);
+        goto out;
+    }
+
+    err = oct_parse_names(buffer, &names, &count);
+    if (err_is_fail(err)) {
+        goto out;
+    }
+
+out:
+    free(buffer);
+    oct_free_names(names, count);
+    if (err_is_fail(err)) {
+        DEBUG_ERR(err, "num_spawnds_online");
+        return 0;
+    }
+    return count;
+}
+
index 6c8ebd7..0da4d21 100644 (file)
@@ -107,4 +107,6 @@ void revoke_ready__rx(struct intermon_binding *b, genvaddr_t st);
 void revoke_commit__rx(struct intermon_binding *b, genvaddr_t st);
 void revoke_done__rx(struct intermon_binding *b, genvaddr_t st);
 
+size_t num_monitors_online(void);
+
 #endif
index 171565b..ef1a31d 100644 (file)
@@ -89,7 +89,7 @@ capops_revoke(struct domcapref cap,
         capops_retrieve(rst->cap, revoke_retrieve__rx, st);
     }
     else {
-        if (num_monitors == 1) {
+        if (num_monitors_online() == 1) {
             DEBUG_CAPOPS("%s: only one monitor: do simpler revoke\n",
                     __FUNCTION__);
             // no remote monitors exist; do simplified revocation process
@@ -170,7 +170,7 @@ revoke_local(struct revoke_master_st *st)
 static void
 revoke_no_remote(struct revoke_master_st *st)
 {
-    assert(num_monitors == 1);
+    assert(num_monitors_online() == 1);
 
     if (!delete_steps_get_waitset()) {
         delete_steps_init(get_default_waitset());
index bcafe79..dc54469 100644 (file)
@@ -71,7 +71,6 @@ extern bool bsp_monitor;
 extern struct capref trace_cap;
 extern struct bootinfo *bi;
 extern bool update_ram_alloc_binding;
-extern int num_monitors;
 
 union capability_caprep_u {
     intermon_caprep_t caprep;