static clib_error_t * sendmsg_helper (mc_socket_main_t * msm, int socket, struct sockaddr_in * tx_addr, u32 buffer_index) { vlib_main_t * vm = msm->mc_main.vlib_main; struct msghdr h; word n_bytes, n_bytes_tx, n_retries; memset (&h, 0, sizeof (h)); h.msg_name = tx_addr; h.msg_namelen = sizeof (tx_addr[0]); if (msm->iovecs) _vec_len (msm->iovecs) = 0; n_bytes = append_buffer_index_to_iovec (vm, buffer_index, &msm->iovecs); ASSERT (n_bytes <= msm->mc_main.transport.max_packet_size); if (n_bytes > msm->mc_main.transport.max_packet_size) clib_error ("sending packet larger than interace MTU %d bytes", n_bytes); h.msg_iov = msm->iovecs; h.msg_iovlen = vec_len (msm->iovecs); n_retries = 0; while ((n_bytes_tx = sendmsg (socket, &h, /* flags */ 0)) != n_bytes && errno == EAGAIN) n_retries++; if (n_bytes_tx != n_bytes) { clib_unix_warning ("sendmsg"); return 0; } if (n_retries) { ELOG_TYPE_DECLARE (e) = { .format = "sendmsg-helper: %d retries", .format_args = "i4", }; struct { u32 retries; } * ed = 0; ed = ELOG_DATA (&vm->elog_main, e); ed->retries = n_retries; } return 0; } static clib_error_t * tx_buffer (void * transport, mc_transport_type_t type, u32 buffer_index) { mc_socket_main_t *msm = (mc_socket_main_t *)transport; vlib_main_t * vm = msm->mc_main.vlib_main; mc_multicast_socket_t * ms = &msm->multicast_sockets[type]; clib_error_t * error; error = sendmsg_helper (msm, ms->socket, &ms->tx_addr, buffer_index); if (type != MC_TRANSPORT_USER_REQUEST_TO_RELAY) vlib_buffer_free_one (vm, buffer_index); return error; }
static void *clib_loadlib(lua_State *L, const char *name, int global) { void *h = (void *)LoadLibraryA(clib_extname(L, name)); if (!h) clib_error(L, "cannot load module " LUA_QS ": %s", name); UNUSED(global); return h; }
static void *clib_loadlib(lua_State *L, const char *name, int global) { DWORD oldwerr = GetLastError(); void *h = (void *)LoadLibraryExA(clib_extname(L, name), NULL, 0); if (!h) clib_error(L, "cannot load module " LUA_QS ": %s", name); SetLastError(oldwerr); UNUSED(global); return h; }
void clib_smp_init (void) { clib_smp_main_t * m = &clib_smp_main; uword cpu; m->vm_base = clib_mem_vm_alloc ((uword) (m->n_cpus + 1) << m->log2_n_per_cpu_vm_bytes); if (! m->vm_base) clib_error ("error allocating virtual memory"); for (cpu = 0; cpu < m->n_cpus; cpu++) clib_calljmp (allocate_per_cpu_mheap, cpu, clib_smp_stack_top_for_cpu (m, cpu)); }
/* Index a C library by name. */ TValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name) { TValue *tv = lj_tab_setstr(L, cl->cache, name); if (LJ_UNLIKELY(tvisnil(tv))) { CTState *cts = ctype_cts(L); CType *ct; CTypeID id = lj_ctype_getname(cts, &ct, name, CLNS_INDEX); if (!id) lj_err_callerv(L, LJ_ERR_FFI_NODECL, strdata(name)); if (ctype_isconstval(ct->info)) { CType *ctt = ctype_child(cts, ct); lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4); if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0) setnumV(tv, (lua_Number)(uint32_t)ct->size); else setintV(tv, (int32_t)ct->size); } else { const char *sym = clib_extsym(cts, ct, name); #if LJ_TARGET_WINDOWS DWORD oldwerr = GetLastError(); #endif void *p = clib_getsym(cl, sym); GCcdata *cd; lua_assert(ctype_isfunc(ct->info) || ctype_isextern(ct->info)); #if LJ_TARGET_X86 && LJ_ABI_WIN /* Retry with decorated name for fastcall/stdcall functions. */ if (!p && ctype_isfunc(ct->info)) { CTInfo cconv = ctype_cconv(ct->info); if (cconv == CTCC_FASTCALL || cconv == CTCC_STDCALL) { CTSize sz = clib_func_argsize(cts, ct); const char *symd = lj_str_pushf(L, cconv == CTCC_FASTCALL ? "@%s@%d" : "_%s@%d", sym, sz); L->top--; p = clib_getsym(cl, symd); } } #endif if (!p) clib_error(L, "cannot resolve symbol " LUA_QS ": %s", sym); #if LJ_TARGET_WINDOWS SetLastError(oldwerr); #endif cd = lj_cdata_new(cts, id, CTSIZE_PTR); *(void **)cdataptr(cd) = p; setcdataV(L, tv, cd); } } return tv; }
int test_random_main (unformat_input_t * input) { uword n_iterations; uword i, repeat_count; uword * bitmap = 0; uword print; u32 seed; u32 *seedp = &seed; /* first, check known sequence from Numerical Recipes in C, 2nd ed. page 284 */ seed = known_random_sequence[0]; for (i = 0; i < ARRAY_LEN(known_random_sequence)-1; i++) { u32 rv; rv = random_u32 (seedp); if (rv != known_random_sequence[i+1]) { fformat(stderr, "known sequence check FAILS at index %d", i+1); break; } } clib_warning ("known sequence check passes"); n_iterations = 1000; seed = 0; print = 1 << 24; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (0 == unformat (input, "iter %d", &n_iterations) && 0 == unformat (input, "print %d", &print) && 0 == unformat (input, "seed %d", &seed)) clib_error ("unknown input `%U'", format_unformat_error, input); } if (! seed) seed = random_default_seed (); if (n_iterations == 0) n_iterations = random_u32_max (); clib_warning ("%d iterations, seed %d\n", n_iterations, seed); repeat_count = 0; for (i = 0; i < n_iterations; i++) { uword r = random_u32 (&seed); uword b, ri, rj; ri = r / BITS (bitmap[0]); rj = (uword) 1 << (r % BITS (bitmap[0])); vec_validate (bitmap, ri); b = bitmap[ri]; if (b & rj) goto repeat; b |= rj; bitmap[ri] = b; if (0 == (i & (print - 1))) fformat (stderr, "0x%08x iterations %d repeats\n", i, repeat_count); continue; repeat: fformat (stderr, "repeat found at iteration %d/%d\n", i, n_iterations); repeat_count++; continue; } return 0; }
int test_standalone_string_main (unformat_input_t * input) { uword iter = 0; uword help = 0; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (0 == unformat (input, "iter %d", &iter) && 0 == unformat (input, "bytes %d", &g_bytes) && 0 == unformat (input, "seed %d", &g_seed) && 0 == unformat (input, "align %d", &g_align) && 0 == unformat (input, "overlap %d", &g_overlap) && 0 == unformat (input, "verbose %d", &g_verbose) && 0 == unformat (input, "swap %=", &g_swap, 1) && 0 == unformat (input, "help %=", &help, 1)) { clib_error ("unknown input `%U'", format_unformat_error, input); goto usage; } } if (help) goto usage; fformat (stdout, "iter %d, bytes %d, seed %u, align %d, overlap %d, " "verbose %d, %s\n", iter, g_bytes, g_seed, g_align, g_overlap, g_verbose, (g_swap) ? "swap" : ""); #if 1 assert_memset (iter); assert_memcpy (iter); assert_memmove (iter); assert_memcmp (iter); assert_strlen (iter); #endif if (g_bytes < 64) { fformat (stdout, "To ensure fairness in timing, the number of bytes " "to process needs to be at least 64\n"); return -1; } #if 1 time_memset (iter); time_memcpy (iter); time_memmove (iter); time_memcmp (iter); time_strcpy (iter); #endif memory_snap (); return 0; usage: fformat (stdout, "Usage: test_standalone_string iter <N> bytes <N> seed <N>\n" " align <N> overlap <N> verbose <N>\n" " swap help\n"); if (help) return 0; return -1; }