Browse Source

Refactor storage processing into its own file

It's just a dummy function for now
Ian Goldberg 1 year ago
parent
commit
b4b14ff140
4 changed files with 58 additions and 10 deletions
  1. 12 9
      Enclave/route.cpp
  2. 34 0
      Enclave/storage.cpp
  3. 9 0
      Enclave/storage.hpp
  4. 3 1
      Makefile

+ 12 - 9
Enclave/route.cpp

@@ -5,6 +5,7 @@
 #include "sort.hpp"
 #include "comms.hpp"
 #include "obliv.hpp"
+#include "storage.hpp"
 #include "route.hpp"
 
 #define PROFILE_ROUTING
@@ -574,13 +575,15 @@ void ecall_routing_proceed(void *cbpointer)
             // Sort the messages we've received
 #ifdef PROFILE_ROUTING
             uint32_t inserted = ingbuf.inserted;
-            unsigned long start = printf_with_rtclock("begin oblivious sort (%u,%u)\n", inserted, route_state.tot_msg_per_ing);
+            unsigned long start_round1 = printf_with_rtclock("begin round1 processing (%u)\n", inserted);
+            unsigned long start_sort = printf_with_rtclock("begin oblivious sort (%u,%u)\n", inserted, route_state.tot_msg_per_ing);
 #endif
             sort_mtobliv(g_teems_config.nthreads, ingbuf.buf,
                 g_teems_config.msg_size, ingbuf.inserted,
                 route_state.tot_msg_per_ing, send_round1_msgs);
 #ifdef PROFILE_ROUTING
-            printf_with_rtclock_diff(start, "end oblivious sort (%u,%u)\n", inserted, route_state.tot_msg_per_ing);
+            printf_with_rtclock_diff(start_sort, "end oblivious sort (%u,%u)\n", inserted, route_state.tot_msg_per_ing);
+            printf_with_rtclock_diff(start_round1, "end round1 processing (%u)\n", inserted);
 #endif
             ingbuf.reset();
             pthread_mutex_unlock(&ingbuf.mutex);
@@ -708,7 +711,6 @@ void ecall_routing_proceed(void *cbpointer)
         }
     } else if (route_state.step == ROUTE_ROUND_2) {
         if (my_roles & ROLE_STORAGE) {
-            uint16_t msg_size = g_teems_config.msg_size;
             MsgBuffer &round2 = route_state.round2;
 
             pthread_mutex_lock(&round2.mutex);
@@ -719,12 +721,13 @@ void ecall_routing_proceed(void *cbpointer)
                 pthread_mutex_lock(&round2.mutex);
             }
 
-            printf("Storage server received %u messages:\n", round2.inserted);
-            const uint8_t *buf = round2.buf;
-            for (uint32_t i=0; i<round2.inserted; ++i) {
-                printf("%08x\n", *(const uint32_t*)buf);
-                buf += msg_size;
-            }
+#ifdef PROFILE_ROUTING
+            unsigned long start = printf_with_rtclock("begin storage processing (%u)\n", round2.inserted);
+#endif
+            storage_received(round2.buf, round2.inserted);
+#ifdef PROFILE_ROUTING
+            printf_with_rtclock_diff(start, "end storage processing (%u)\n", round2.inserted);
+#endif
 
             round2.reset();
             pthread_mutex_unlock(&round2.mutex);

+ 34 - 0
Enclave/storage.cpp

@@ -0,0 +1,34 @@
+#include "utils.hpp"
+#include "config.hpp"
+#include "storage.hpp"
+
+// Handle the messages received by a storage node
+void storage_received(const uint8_t *msgs, uint32_t num_msgs)
+{
+    // A dummy function for now that just counts how many real and
+    // padding messages arrived
+    uint16_t msg_size = g_teems_config.msg_size;
+    nodenum_t my_node_num = g_teems_config.my_node_num;
+    uint32_t real = 0, padding = 0;
+    uint32_t uid_mask = (1 << DEST_UID_BITS) - 1;
+
+    printf("Storage server received %u messages:\n", num_msgs);
+    for (uint32_t i=0; i<num_msgs; ++i) {
+        uint32_t dest_addr = *(const uint32_t*)msgs;
+        nodenum_t dest_node =
+            g_teems_config.storage_map[dest_addr >> DEST_UID_BITS];
+        if (dest_node != my_node_num) {
+            char hexbuf[2*msg_size + 1];
+            for (uint32_t j=0;j<msg_size;++j) {
+                snprintf(hexbuf+2*j, 3, "%02x", msgs[j]);
+            }
+            printf("Misrouted message: %s\n", hexbuf);
+        } else if ((dest_addr & uid_mask) == uid_mask) {
+            ++padding;
+        } else {
+            ++real;
+        }
+        msgs += msg_size;
+    }
+    printf("%u real, %u padding\n", real, padding);
+}

+ 9 - 0
Enclave/storage.hpp

@@ -0,0 +1,9 @@
+#ifndef __STORAGE_HPP__
+#define __STORAGE_HPP__
+
+#include <cstdint>
+
+// Handle the messages received by a storage node
+void storage_received(const uint8_t *msgs, uint32_t num_msgs);
+
+#endif

+ 3 - 1
Makefile

@@ -305,8 +305,10 @@ Enclave/config.o: Enclave/enclave_api.h Enclave/config.hpp Enclave/route.hpp
 Enclave/obliv.o: Enclave/enclave_api.h Enclave/obliv.hpp
 Enclave/route.o: Enclave/Enclave_t.h Enclave/enclave_api.h Enclave/config.hpp
 Enclave/route.o: Enclave/enclave_api.h Enclave/sort.hpp Enclave/comms.hpp
-Enclave/route.o: Enclave/obliv.hpp Enclave/route.hpp
+Enclave/route.o: Enclave/obliv.hpp Enclave/storage.hpp Enclave/route.hpp
 Enclave/sort.o: Enclave/sort.hpp
+Enclave/storage.o: Enclave/config.hpp Enclave/enclave_api.h
+Enclave/storage.o: Enclave/storage.hpp
 Enclave/OblivAlgs/RecursiveShuffle.o: Enclave/OblivAlgs/oasm_lib.h
 Enclave/OblivAlgs/RecursiveShuffle.o: Enclave/OblivAlgs/CONFIG.h
 Enclave/OblivAlgs/RecursiveShuffle.o: Enclave/OblivAlgs/oasm_lib.tcc