void fastsocket_init(void) { int ret = 0; int i; cpu_set_t cmask; ret = open("/dev/fastsocket", O_RDONLY); if (ret < 0) { FSOCKET_ERR("Open fastsocket channel failed, please CHECK\n"); /* Just exit for safty*/ exit(-1); } fsocket_channel_fd = ret; fsocket_fd_set = calloc(INIT_FDSET_NUM, sizeof(int)); if (!fsocket_fd_set) { FSOCKET_ERR("Allocate memory for listen fd set failed\n"); exit(-1); } fsocket_fd_num = INIT_FDSET_NUM; CPU_ZERO(&cmask); for (i = 0; i < get_cpus(); i++) CPU_SET(i, &cmask); ret = sched_setaffinity(0, get_cpus(), &cmask); if (ret < 0) { FSOCKET_ERR("Clear process CPU affinity failed\n"); exit(-1); } return; }
/* @details -# Loop forever for new connections -# create a new VariableServerThread when new conection found -# create new VariableServerThread thread */ void * Trick::JSONVariableServer::thread_body() { fd_set rfds; struct timeval timeout_time = { 2, 0 }; while (1) { FD_ZERO(&rfds); FD_SET(listen_dev.socket, &rfds); timeout_time.tv_sec = 2 ; select(listen_dev.socket + 1, &rfds, NULL, NULL, &timeout_time); if (FD_ISSET(listen_dev.socket, &rfds)) { Trick::JSONVariableServerThread * vst = new Trick::JSONVariableServerThread(&listen_dev) ; vst->copy_cpus(get_cpus()) ; vst->create_thread() ; } } return NULL ; }
/** * @brief * read nodes and get topology * */ void schd_get_topology(void) { char *whoami = "schd_get_topology"; DIR *dirp; struct dirent *dent; char *digits ="0123456789"; char path[MAXPATHLEN]; char realpath[MAXPATHLEN]; char realpath2[MAXPATHLEN]; int len; struct node *p; int i; int j; char *s; int max_nasid = -1; #ifdef HAVE_HUBSTAT_H int fd; hubstat_t hs; #endif /*================================================*/ /* if not our first time, we need to give back a */ /* bunch of heap space before we get started here */ /*================================================*/ cleanup_topology_data(); n_cpus = sysmp(MP_NPROCS); /*=======================================*/ /* figure out just which nodes we've got */ /*=======================================*/ if ((dirp=opendir(HW_NODENUM_PATH)) == NULL) { sprintf(log_bfr, "opendir(%s)", HW_NODENUM_PATH); log_err(errno, whoami, log_bfr); exit(EXIT_FAILURE); } rewinddir(dirp); while (dent=readdir(dirp)) { /* only want those whose names consist solely of digits */ if (strspn(dent->d_name, digits) < strlen(dent->d_name)) continue; sprintf(path, "%s/%s", HW_NODENUM_PATH, dent->d_name); if ((len = readlink(path, realpath, sizeofrealpath)) < 0) { sprintf(log_bfr, "readlink(%s)", path); log_err(errno, whoami, log_bfr); continue; } realpath[len] = '\0'; /* 'readlink()' punts on this */ p = malloc(sizeof*p); if (p == NULL) { strcpy(log_bfr, "malloc failed"); log_err(errno, whoami, log_bfr); return; /* probably a BAD choice */ } p->logical_nbr = atoi(dent->d_name); strcat(path, HW_PATH_SUFFIX); #ifdef HAVE_HUBSTAT_H if ((fd=open(path, O_RDONLY)) < 0) { sprintf(log_bfr, "open(%s)", path); log_err(errno, whoami, log_bfr); continue; /* ??? */ } if (ioctl(fd, SN0DRV_GET_HUBINFO, &hs) < 0) { sprintf(log_bfr, "ioctl(%s,GET_HUBINFO)", path); log_err(errno, whoami, log_bfr); continue; /* as before: ??? */ } close(fd); p->physical_nbr = hs.hs_nasid; #else p->physical_nbr = p->logical_nbr; #endif if (max_nasid < p->physical_nbr) max_nasid = p->physical_nbr; p->next = NULL; s = strstr(realpath, "slot/"); if (s) { /* Origin2000 */ p->slot = atoi(s+5); s = strstr(realpath, "module/"); p->module = atoi(s+7); p->rack = 0; } else { /* Origin3000 */ s = strstr(realpath, "module/"); p->rack = atoi(s+7); p->module = 0; p->slot = 0; } for (i=0 ; i < MAX_CPUS_PER_NODE ; ++i) p->cpu[i] = -1; strcpy(realpath2, realpath); strcat(realpath, "/cpu"); get_cpus(realpath, p->cpu); strcat(realpath2, "/memory"); get_mem(realpath2, &p->memory); /* add this one to our list */ if (n_nodes == 0) first_node = p; else last_node->next = p; last_node = p; ++n_nodes; } closedir(dirp); /* linearize */ if (n_nodes) { Nodes = malloc(n_nodes*sizeof*Nodes); if (Nodes == NULL) { sprintf(log_bfr, "malloc(%d nodes)", n_nodes); log_err(errno, whoami, log_bfr); return; } i = 0; p = first_node; while (p) { Nodes[i] = *p; free(p); p = Nodes[i++].next; } first_node = last_node = NULL; /* empirically, next is *unnecessary* */ qsort(Nodes, n_nodes, sizeof*Nodes, cmp_nodes); } /*===========================================================*/ /* now for the Whole Point(tm): determine the permutation */ /* that maps "logical" to "physical" node numbers. And its */ /* inverse, while we're at it [as it's useful down the road] */ /*===========================================================*/ ++max_nasid; schd_nodes_log2phys = malloc(max_nasid*sizeof*schd_nodes_log2phys); if (schd_nodes_log2phys == NULL) { strcpy(log_bfr, "malloc(schd_nodes_log2phys)"); log_err(errno, whoami, log_bfr); return; } schd_nodes_phys2log = malloc(max_nasid*sizeof*schd_nodes_phys2log); if (schd_nodes_phys2log == NULL) { strcpy(log_bfr, "malloc(schd_nodes_phys2log)"); log_err(errno, whoami, log_bfr); return; } for (j=0 ; j < max_nasid ; ++j) schd_nodes_log2phys[j] = schd_nodes_phys2log[j] = -1; for (i=0 ; i < n_nodes ; ++i) { j = Nodes[i].physical_nbr; schd_nodes_log2phys[i] = j; schd_nodes_phys2log[j] = i; } return; }
int main(int argc, char** argv) { int n = 0; int i; const int MAX = atoi(argv[1]); const int CORES = atoi(argv[2]); int ncpus=0; int apps[1024]; /**/ extern char *optarg; extern int optind, opterr, optopt; int ret = 0, cont = 1; unsigned int cpu = 0; //unsigned int cpu_defined = 0; unsigned long min_available_freq = 0; unsigned long max_available_freq = 0; unsigned long current_freq = 0; unsigned long initial_freq = 0; struct cpufreq_available_frequencies *freqs; int retr =0; setlinebuf(stdout); ncpus=get_cpus(); if(!CORES){ CORES == ncpus; } if (CORES > ncpus){ printf("Wrong number of inital cores"); exit(2); } ret= get_hardware_limits(cpu); min_available_freq = min; max_available_freq = max; ret= set_policy(CORES); freqs = cpufreq_get_available_frequencies(0); /*if (freqs==null){ goto out; }*/ current = get_available_freqs_size(freqs); unsigned long* available_freqs = (unsigned long *) malloc(current*sizeof(unsigned long)); ret = store_available_freqs( freqs, available_freqs, current); int current_counter = get_init_frequency(available_freqs, cpu); /*if (ret!=0){ goto out; }*/ current_freq = cpufreq_get_freq_kernel(cpu); if(getenv("HEARTBEAT_ENABLED_DIR") == NULL) { fprintf(stderr, "ERROR: need to define environment variable HEARTBEAT_ENABLED_DIR (see README)\n"); return 1; } heart_data_t* records = (heart_data_t*) malloc(MAX*sizeof(heart_data_t)); int last_tag = -1; while(n == 0) { n = get_heartbeat_apps(apps); } printf("apps[0] = %d\n", apps[0]); // For this test we only allow one heartbeat enabled app // assert(n==1); if (n>1) { printf("too many apps!!!!!!!!!!!!!!\n"); exit(2); } /* sleep(5);*/ #if 1 int rc = heart_rate_monitor_init(&heart, apps[0]); if (rc != 0) printf("Error attaching memory\n"); printf("buffer depth is %lld\n", (long long int) heart.state->buffer_depth); i = 0; printf(" rate interval is %f - %f\n", hrm_get_min_rate(&heart), hrm_get_max_rate(&heart)); printf("beat\trate\tfreq\tcores\ttact\twait\n"); int64_t window_size = hrm_get_window_size(&heart); int wait_for = (int) window_size; int current_beat = 0; int current_beat_prev= 0; int nprocs = 1; unsigned int set_freq = min; // return 1; while(current_beat < MAX) { int rc = -1; heartbeat_record_t record; char command[256]; while (rc != 0 || record.window_rate == 0.0000 ){ rc = hrm_get_current(&heart, &record); current_beat = record.beat; } if(current_beat_prev == current_beat) continue; /* printf(" rc: %d, current_beat:%d \n", rc,current_beat);*/ /*Situation where doesn't happen nothing*/ if( current_beat < wait_for){ current_beat_prev= current_beat; /* printf("I am in situation wait_for\n");*/ current_freq = cpufreq_get_freq_kernel(0); print_status(&record, wait_for, current_freq, '.', CORES); continue; } /* printf("Current beat is %d, wait_for = %d, %f\n", current_beat, wait_for, record.window_rate);*/ /*Situation where frequency is up-scaled*/ if(record.window_rate < hrm_get_min_rate(&heart)) { wait_for = current_beat + window_size; if (current_counter > 0){ int cpu; current_counter--; set_freq = get_speed(available_freqs[current_counter]); for (cpu=0; cpu <=CORES; cpu++) { /* sprintf(command, "cpufreq-set -c %d -f %luMHZ", cpu,set_freq);*/ /* printf("Executing %s\n", command);*/ /* system(command);*/ cpufreq_set_frequency(cpu, available_freqs[current_counter]); } current_freq = cpufreq_get_freq_kernel(0); print_status(&record, wait_for, current_freq, '+', CORES); } else { current_freq = cpufreq_get_freq_kernel(0); print_status(&record, wait_for, current_freq, 'M', CORES); } } /*Situation where frequency is downscaled*/ else if(record.window_rate > hrm_get_max_rate(&heart)) { wait_for = current_beat + window_size; if (current_counter < current){ current_counter++; set_freq = get_speed(available_freqs[current_counter]); for (cpu=0; cpu <=CORES; cpu++) { /* sprintf(command, " cpufreq-set -c %d -f %uMHZ", cpu,set_freq);*/ /* printf("Executing %s\n", command);*/ /*system(command);*/ cpufreq_set_frequency(cpu, available_freqs[current_counter]); } current_freq = cpufreq_get_freq_kernel(0); print_status(&record, wait_for, current_freq, '-', CORES); } else { current_freq = cpufreq_get_freq_kernel(0); print_status(&record, wait_for, current_freq, 'm', CORES); } } else { wait_for = current_beat+1; print_status(&record, wait_for, current_freq, '=', CORES); } current_beat_prev= current_beat; records[i].tag = current_beat; records[i].rate = record.window_rate; i++; } //printf("System: Global heart rate: %f, Current heart rate: %f\n", heart.global_heartrate, heart.window_heartrate); /* for(i = 0; i < MAX; i++) { printf("%d, %f\n", records[i].tag, records[i].rate); }*/ heart_rate_monitor_finish(&heart); #endif return 0; }
static int cpufreq_constructor(Plugin *p, char** fp) { cpufreq *cf; GtkWidget *button; ENTER; cf = g_new0(cpufreq, 1); cf->governors = NULL; cf->cpus = NULL; g_return_val_if_fail(cf != NULL, 0); p->priv = cf; p->pwid = gtk_event_box_new(); GTK_WIDGET_SET_FLAGS( p->pwid, GTK_NO_WINDOW ); gtk_container_set_border_width( GTK_CONTAINER(p->pwid), 2 ); cf->namew = gtk_image_new_from_file(PROC_ICON); gtk_container_add(GTK_CONTAINER(p->pwid), cf->namew); cf->main = p->pwid; cf->tip = gtk_tooltips_new(); #if GLIB_CHECK_VERSION( 2, 10, 0 ) g_object_ref_sink( cf->tip ); #else g_object_ref( cf->tip ); gtk_object_sink( cf->tip ); #endif g_signal_connect (G_OBJECT (p->pwid), "button_press_event", G_CALLBACK (clicked), (gpointer) p); cf->has_cpufreq = 0; get_cpus(cf); /* line s; s.len = 256; if (fp) { while (lxpanel_get_line(fp, &s) != LINE_BLOCK_END) { if (s.type == LINE_NONE) { ERR( "cpufreq: illegal token %s\n", s.str); goto error; } if (s.type == LINE_VAR) { if (!g_ascii_strcasecmp(s.t[0], "DefaultGovernor")){ //cf->str_cl_normal = g_strdup(s.t[1]); }else { ERR( "cpufreq: unknown var %s\n", s.t[0]); continue; } } else { ERR( "cpufreq: illegal in cfis context %s\n", s.str); goto error; } } }*/ update_tooltip(cf); cf->timer = g_timeout_add(2000, (GSourceFunc)update_tooltip, (gpointer)cf); gtk_widget_show(cf->namew); RET(TRUE); /*error: RET(FALSE);*/ }
int main(int argn, char **argv) { // Init SDL if(SDL_Init(SDL_INIT_VIDEO) != 0) fprintf(stderr, "Could not initialize SDL2: %s\n", SDL_GetError()); printf("SDL Initialized\n"); // Create screen texture SDL_Surface *screen, *message; int res_x = 800; int res_y = 600; int julia_mode = 0; if(argn == 1) { julia_mode = 0; } else if ((argn == 2) && (strcmp(argv[1], "-julia") == 0)) { julia_mode = 1; printf("Julia mode activated.\n"); } int number_cores = get_cpus(); int number_threads = number_cores * number_cores; printf("Number of CPUs/cores autodetected: %d\n", number_cores); #ifdef CACHE // Init our cached points cached_points = malloc(res_y * 1000 * sizeof(int *)); cached_x = malloc(res_y * 1000 * sizeof(float *)); cached_y = malloc(res_y * 1000 * sizeof(float *)); if (cached_points == NULL) { fprintf(stderr, "Bad luck, out of memory\n"); return 2; } int count; for (count = 0; count < res_y * 1000; count++) { cached_points[count] = malloc(res_x * 1000 * sizeof(int)); if(cached_points[count] == NULL) { fprintf(stderr, "Bad luck, out of memory\n"); return 2; } cached_x[count] = malloc(res_x * 1000 * sizeof(float)); cached_y[count] = malloc(res_x * 1000 * sizeof(float)); /*for (count2 = 0; count2 < res_x * 100; count2++) { cached_points[count][count2] = -1; }*/ } printf("Cache ready\n"); #endif // screen = SDL_SetVideoMode(res_x, res_y, 0, SDL_HWSURFACE|SDL_DOUBLEBUF); // screen = SDL_SetVideoMode(res_x, res_y, 0, SDL_DOUBLEBUF); SDL_Window *window = SDL_CreateWindow("MandelClassic", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, res_x, res_y, 0); SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0); if ((!window) || (!renderer)) fprintf(stderr,"Could not set video mode: %s\n",SDL_GetError()); // Blank the window SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); SDL_RenderClear(renderer); SDL_RenderPresent(renderer); SDL_Texture *texture_screen = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, res_x, res_y); screen = SDL_CreateRGBSurface(0, res_x, res_y , 32, 0, 0, 0, 0); //Initialize SDL_ttf if( TTF_Init() == -1 ) { printf("Error setting up TTF module.\n"); return 1; } // Load a font TTF_Font *font; font = TTF_OpenFont("font.ttf", 24); if (font == NULL) { printf("TTF_OpenFont() Failed: %s", TTF_GetError()); SDL_Quit(); return 1; } //The color of the font SDL_Color textColor = { 255, 255, 255 }; // Prepare the resolution and sizes and colors, threads... iteration_pixels = malloc(res_x * res_y * sizeof(int)); pthread_t threads[number_threads]; piece_args arguments[number_threads]; printf("Rendering...\n"); float zoom = 1.0; float stop_point; if (julia_mode == 0) stop_point = 0.00001; else stop_point = -2.5; // We measure the time to do the zooming clock_t start = clock(); while(zoom > stop_point) { int iteration, max_iteration, x, y, res; if((zoom < -0.02) && (zoom > -1.0)) { max_iteration = 100; } else { max_iteration = 170; } int thread_count; for(thread_count = 0; thread_count < number_threads; thread_count++) { arguments[thread_count].res_x = res_x; arguments[thread_count].res_y = res_y; arguments[thread_count].zoom = zoom; arguments[thread_count].max_iteration = max_iteration; arguments[thread_count].total_threads = number_threads; arguments[thread_count].thread_number = thread_count; arguments[thread_count].julia_mode = julia_mode; pthread_create( &threads[thread_count], NULL, thread_launcher, (void*) &arguments[thread_count]); } for(thread_count = 0; thread_count < number_threads; thread_count++) { res = pthread_join(threads[thread_count], NULL); if (res != 0) { printf("Error in %d thread\n", thread_count); } } int rank; Uint32 *pixel; rank = screen->pitch/sizeof(Uint32); pixel = (Uint32*)screen->pixels; for(y = 0; y < res_y ; y++) { for(x = 0; x < res_x; x++) { iteration = iteration_pixels[x + y * res_x]; if ((iteration < 128) && (iteration > 0)) { pixel[x + y * rank] = SDL_MapRGBA(screen->format, 0, 20 + iteration, 0, 255); } else if ((iteration >= 128) && (iteration < max_iteration)) { pixel[x + y * rank] = SDL_MapRGBA(screen->format, iteration, 148, iteration, 255); } else { pixel[x + y * rank] = SDL_MapRGBA(screen->format, 0, 0, 0, 255); } } } if(julia_mode == 0) zoom = zoom * 0.99; else zoom -= 0.01; // Draw message on a corner... char* msg = (char *)malloc(100 * sizeof(char)); sprintf(msg, "Zoom level: %0.3f", zoom * 100.0); message = TTF_RenderText_Solid( font, msg, textColor ); free(msg); if (message != NULL) SDL_BlitSurface(message, NULL, screen, NULL); free(message); SDL_UpdateTexture(texture_screen, NULL, (Uint32*)screen->pixels, 800 * sizeof (Uint32)); SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture_screen, NULL, NULL); SDL_RenderPresent(renderer); // SDL_Flip(screen); } printf("Time elapsed %0.5f seconds\n", ((double)clock() - start) / CLOCKS_PER_SEC); SDL_Event ev; int active; active = 1; while(active) { /* Handle events */ while(SDL_PollEvent(&ev)) { if(ev.type == SDL_QUIT) active = 0; /* End */ } } SDL_Quit(); return 0; }