/* run-time CPU detection */ static UCS_F_NOOPTIMIZE void ucs_check_cpu_flags(void) { char str[256]; char *p_str; int cpu_flags; struct { const char* flag; ucs_cpu_flag_t value; } *p_flags, cpu_flags_array[] = { { "cmov", UCS_CPU_FLAG_CMOV }, { "mmx", UCS_CPU_FLAG_MMX }, { "mmx2", UCS_CPU_FLAG_MMX2 }, { "sse", UCS_CPU_FLAG_SSE }, { "sse2", UCS_CPU_FLAG_SSE2 }, { "sse3", UCS_CPU_FLAG_SSE3 }, { "ssse3", UCS_CPU_FLAG_SSSE3 }, { "sse41", UCS_CPU_FLAG_SSE41 }, { "sse42", UCS_CPU_FLAG_SSE42 }, { "avx", UCS_CPU_FLAG_AVX }, { "avx2", UCS_CPU_FLAG_AVX2 }, { NULL, UCS_CPU_FLAG_UNKNOWN }, }; cpu_flags = ucs_arch_get_cpu_flag(); if (UCS_CPU_FLAG_UNKNOWN == cpu_flags) { return ; } strncpy(str, UCS_PP_MAKE_STRING(CPU_FLAGS), sizeof(str) - 1); p_str = strtok(str, " |\t\n\r"); while (p_str) { p_flags = cpu_flags_array; while (p_flags && p_flags->flag) { if (!strcmp(p_str, p_flags->flag)) { if (!(cpu_flags & p_flags->value)) { fprintf(stderr, "[%s:%d] FATAL: UCX library was compiled with %s" " but CPU does not support it.\n", ucs_get_host_name(), getpid(), p_flags->flag); exit(1); } break; } p_flags++; } if (NULL == p_flags->flag) { fprintf(stderr, "[%s:%d] FATAL: UCX library was compiled with %s" " but CPU does not support it.\n", ucs_get_host_name(), getpid(), p_str); exit(1); } p_str = strtok(NULL, " |\t\n\r"); } }
static uint64_t __sumup_host_name(unsigned prime_index) { uint64_t sum, n; const char *p; unsigned i; sum = 0; i = prime_index; p = ucs_get_host_name(); while (*p != '\0') { n = 0; strncpy((char*)&n, p, sizeof(n)); sum += ucs_get_prime(i) * n; ++i; p += ucs_min(sizeof(n), strlen(p)); } return sum; }
static ucs_status_t uct_posix_set_path(char *file_name, int use_shm_open, const char *path, uint64_t uuid) { ucs_status_t status; int ret, len; if (!use_shm_open) { strncpy(file_name, path, NAME_MAX); } len = strlen(file_name); ret = snprintf(file_name + len, NAME_MAX - len, "/ucx_posix_mm_%s_%s_%016lx", ucs_get_user_name(), ucs_get_host_name(), uuid); if ((ret >= (NAME_MAX - len)) || (ret < 1)) { status = UCS_ERR_INVALID_PARAM; return status; } return UCS_OK; }
void ucs_log_init() { const char *next_token; if (ucs_log_initialized) { return; } ucs_log_initialized = 1; /* Set this to 1 immediately to avoid infinite recursion */ strcpy(ucs_log_hostname, ucs_get_host_name()); ucs_log_file = stdout; ucs_log_file_close = 0; ucs_log_push_handler(ucs_log_default_handler); if (strlen(ucs_global_opts.log_file) != 0) { ucs_open_output_stream(ucs_global_opts.log_file, &ucs_log_file, &ucs_log_file_close, &next_token); } ucs_debug("%s loaded at 0x%lx", ucs_debug_get_lib_path(), ucs_debug_get_lib_base_addr()); }
void ucs_fill_filename_template(const char *tmpl, char *buf, size_t max) { char *p, *end; const char *pf, *pp; size_t length; time_t t; p = buf; end = buf + max - 1; *end = 0; pf = tmpl; while (*pf != 0 && p < end) { pp = strchr(pf, '%'); if (pp == NULL) { strncpy(p, pf, end - p); p = end; break; } length = ucs_min(pp - pf, end - p); strncpy(p, pf, length); p += length; switch (*(pp + 1)) { case 'p': snprintf(p, end - p, "%d", getpid()); pf = pp + 2; p += strlen(p); break; case 'h': snprintf(p, end - p, "%s", ucs_get_host_name()); pf = pp + 2; p += strlen(p); break; case 'c': snprintf(p, end - p, "%02d", ucs_get_first_cpu()); pf = pp + 2; p += strlen(p); break; case 't': t = time(NULL); strftime(p, end - p, "%Y-%m-%d-%H:%M:%S", localtime(&t)); pf = pp + 2; p += strlen(p); break; case 'u': snprintf(p, end - p, "%s", basename(ucs_get_user_name())); pf = pp + 2; p += strlen(p); break; case 'e': snprintf(p, end - p, "%s", basename(ucs_get_exe())); pf = pp + 2; p += strlen(p); break; default: *(p++) = *pp; pf = pp + 1; break; } p += strlen(p); } *p = 0; }