static int data_cb(const struct nlmsghdr *nlh, void *data) { struct nlattr *tb[CTA_MAX+1] = {}; struct nfgenmsg *nfg = mnl_nlmsg_get_payload(nlh); mnl_attr_parse(nlh, sizeof(*nfg), data_attr_cb, tb); if (tb[CTA_TUPLE_ORIG]) print_tuple(tb[CTA_TUPLE_ORIG]); if (tb[CTA_MARK]) printf("mark=%u ", ntohl(mnl_attr_get_u32(tb[CTA_MARK]))); if (tb[CTA_SECMARK]) printf("secmark=%u ", ntohl(mnl_attr_get_u32(tb[CTA_SECMARK]))); if (tb[CTA_COUNTERS_ORIG]) { printf("original "); print_counters(tb[CTA_COUNTERS_ORIG]); } if (tb[CTA_COUNTERS_REPLY]) { printf("reply "); print_counters(tb[CTA_COUNTERS_REPLY]); } printf("\n"); return MNL_CB_OK; }
static bool check_counters(struct db_context *db, TDB_DATA data) { int i; uint32_t *counters, *old_counters; counters = (uint32_t *)data.dptr; old_counters = (uint32_t *)old_data.dptr; /* check that all the counters are monotonic increasing */ for (i=0; i < old_data.dsize/sizeof(uint32_t); i++) { if (counters[i] < old_counters[i]) { printf("[%4u] ERROR: counters has decreased for node %u From %u to %u\n", (unsigned int)getpid(), i, old_counters[i], counters[i]); success = false; return false; } } if (old_data.dsize != data.dsize) { old_data.dsize = data.dsize; old_data.dptr = (unsigned char*)talloc_realloc_size(db, old_data.dptr, old_data.dsize); } memcpy(old_data.dptr, data.dptr, data.dsize); if (verbose) print_counters(); return true; }
static void handle_signal(struct signalfd_siginfo *fdsi) { switch (fdsi->ssi_signo) { case SIGINT: /* Try to terminate the child processes, if this * succeeds, we'll get a SIGCHLD for each child * process and eventually terminate ourselves. */ fprintf(stderr, "Sending SIGTERM to child processes.\n"); processes_kill(SIGTERM); break; case SIGUSR1: print_counters(stderr); break; case SIGCHLD: { bench_process_t *p = process_find(fdsi->ssi_pid); assert(p); p->zombie = 1; if (run_state == RUN_STATE_RUNNING) /* Kill all running child processes */ processes_kill(SIGTERM); run_state = processes_running() == 0 ? RUN_STATE_EXIT : RUN_STATE_WAITING; } break; default: /* Ignore other signals */ break; } }
static int do_start() { int sfd; int exit_status = EXIT_SUCCESS; catch_fatal_signals(); sfd = create_signal_fd(); for (int i = 0; i < num_processes; i++) { bench_process_t *p = processes + i; p->pid = ctrs_execvp_cb(&p->ctrs, -1 /* cpu */, 0 /* flags */, &setup_child, p, p->argv[0], p->argv); EXPECT(p->pid != -1); } run_state = RUN_STATE_RUNNING; while (run_state != RUN_STATE_EXIT) { struct pollfd pfd[] = { { sfd, POLLIN, 0 } }; EXPECT_ERRNO(poll(pfd, sizeof(pfd) / sizeof(*pfd), -1) != -1); if (pfd[0].revents & POLLIN) { struct signalfd_siginfo fdsi; EXPECT(read(sfd, &fdsi, sizeof(fdsi)) == sizeof(fdsi)); handle_signal(&fdsi); } } print_counters(stderr); for (int i = 0; i < num_processes; i++) { bench_process_t *p = processes + i; int status; EXPECT(waitpid(p->pid, &status, 0) != -1); if (WIFEXITED(status)) { if (WEXITSTATUS(status)) fprintf(stderr, "Child %i: Exit status %i\n", i, WEXITSTATUS(status)); exit_status = EXIT_FAILURE; } else if (WIFSIGNALED(status)) { if (WTERMSIG(status) != SIGTERM) fprintf(stderr, "Child %i: Unexpected exit signal: %i\n", i, WTERMSIG(status)); exit_status = EXIT_FAILURE; } else { fprintf(stderr, "Child %i: Unhandled exit status\n", i); exit_status = EXIT_FAILURE; } } return exit_status; }
static void each_second(struct event_context *ev, struct timed_event *te, struct timeval t, void *private_data) { struct ctdb_context *ctdb = talloc_get_type(private_data, struct ctdb_context); print_counters(); event_add_timed(ev, ctdb, timeval_current_ofs(1, 0), each_second, ctdb); }
static void process_interval(void) { struct timespec ts, rs; read_counters(false); clock_gettime(CLOCK_MONOTONIC, &ts); diff_timespec(&rs, &ts, &ref_time); print_counters(&rs, 0, NULL); }
int main(int argc, char *argv[]) { int i = 1, remaining = argc - 1; if (remaining > 0 && strcmp(argv[i], "-t") == 0) { technical = 1; remaining--; i++; } if (remaining > 0 && strcmp(argv[i], "-q") == 0) { quiet = 1; remaining--; i++; } if (remaining > 0 && strcmp(argv[i], "-t") == 0) { technical = 1; remaining--; i++; } if (remaining != 2) { usage("wrong number of arguments"); } else { FILE *data_input = fopen(argv[i], "r"); assert(data_input); FILE *output = fopen(argv[i + 1], "w"); assert(output); read_data(data_input); compare_pairs(); print_counters(); init_scores_and_sort(); print_pairs(); mark_for_output(); recalc_relevant_for_output(output); return 0; } }
/** check_print_counters * Checks if the counters are ready to be printed * * Parameters: * struct elem *fe - the file element that is currently being worked on */ void check_print_counters(struct elem *fe, struct Globals *gl){ unsigned int my_flags; my_flags = gl->my_flags; pthread_mutex_lock(&mu); //fprintf(stderr, "\t\tREMOVE1\n"); if(fe != NULL){ combine_counters(fe->file->counters, gl); //fprintf(stderr, "\t\tREMOVE2\n"); cstack_remove(fe); } if(!(gl->is_network)){ if(get_head_count() == 0 && *(gl->donecmdln) && *(gl->num_networking) == 0){ if((my_flags&PRINT_COUNTERS) == PRINT_COUNTERS && (*(gl->final_counters))->files_read != 0){ print_counters(gl); (*(gl->is_printed)) = true; } } } pthread_mutex_unlock(&mu); /*check_print_counters*/ }
int main (int argc, char ** argv) { int ret, status, i = 0; pid_t rt_child; timer_t tid; struct sigaction sa; struct sigevent sigev; struct itimerspec new_tmr; struct sched_param s_param; cpu_set_t mask; scheduler_check_arguments(argc, argv); //--------------------------------PAPI initilization------------------------------// init_papi(); scheduler_init_papi(); set_option(); scheduler_set_option(); add_events(); scheduler_add_event(); //---------------------------Timer initialization and sigaction----------------------// sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = timer_handler; sigemptyset(&sa.sa_mask); if(sigaction(SIGRTMIN, &sa, NULL) == -1){ perror("Sigaction"); exit(2); } if(sigaction(SIGCONT, &sa, NULL) == -1){ perror("Sigaction"); exit(2); } sigev.sigev_notify = SIGEV_SIGNAL; sigev.sigev_signo = SIGRTMIN; sigev.sigev_value.sival_ptr = &tid; if(timer_create(CLOCK_REALTIME, &sigev, &tid) != -1){ new_tmr.it_value.tv_sec = 0; new_tmr.it_value.tv_nsec = 25000000; new_tmr.it_interval.tv_sec = 0; new_tmr.it_interval.tv_nsec = 25000000; } /**********************************************************************************************/ //Launch the attackers printf("Launching %d attackers\n", atoi(argv[2])); for(i=0; i < atoi(argv[2]); i++){ if((pid_attacker[nb_attackers++] = fork()) == 0){ CPU_ZERO(&mask); CPU_SET(i+2, &mask); printf("Core %d\n", i+2); if(sched_setaffinity(getpid(), sizeof(mask), &mask)){ fprintf(stderr, "Sched error: set affinity\n"); exit(16); } char c[2]; sprintf(c, "%d", i+2); if(execl("/usr/bin/xterm", "xterm", "-hold", "-e", "./bin/attack_task", "1", c, NULL) == -1){ exit(17); } exit(0); } } sleep(10); /**********************************************************************************************/ /**********************************************************************************************/ //Child executes the RT task in one core if((rt_child = fork())==0){ int stdin_fd = -1; //Setting the affinity of the child //Using only one CPU with max priority CPU_ZERO(&mask); CPU_SET(1, &mask); stdin_fd = open("/dev/null", O_RDONLY); if(stdin_fd == -1) exit(127); dup2(stdin_fd, 1); dup2(stdin_fd, 2); close(stdin_fd); s_param.sched_priority = sched_get_priority_max(SCHED_FIFO); if(sched_setaffinity(getpid(), sizeof(mask), &mask)){ fprintf(stderr, "Sched error: set affinity\n"); exit(16); } if(sched_setscheduler(getpid(), SCHED_FIFO, &s_param)){ fprintf(stderr, "Sched error: sched_setscheduler\n"); exit(17); } if(execl(argv[1], "RT task", NB_RT_ITERATION, NULL) == -1){ fprintf(stderr, "Execl error: Couldn't launch RT exec\n"); exit(17); } exit(0); }else if(rt_child == -1){ fprintf(stderr, "Fork: couldn't create the RT child.\n"); exit(16); /**********************************************************************************************/ //The scheduler }else{ sleep(1); //<= Waiting for stationnary period if(timer_settime(tid, 0, &new_tmr, NULL) == -1){ perror("Timer_settime"); exit(3); } // Launch the counters and the timer if((ret = PAPI_start(PAPI_EventSet)) != PAPI_OK){ fprintf(stderr, "PAPI error: failed to start counters: %s\n", PAPI_strerror(ret)); exit(16); } if((ret = PAPI_start(scheduler_eventset)) != PAPI_OK){ fprintf(stderr, "PAPI error: failed to start counters: %s\n", PAPI_strerror(ret)); exit(16); } struct timeval tv1, tv2; gettimeofday(&tv1, NULL); // Wait for RT child to finish, then kill attackers ret = -1; while(ret != rt_child){ ret = waitpid(rt_child, &status, 0); } if (!WIFEXITED(status)) { fprintf(stderr, "scheduler: Child exited with wrong status\n"); exit(16); } for(i=0; i<nb_attackers; i++){ fprintf(stderr, "\nScheduler (%d) > Sending signal to %d\n", getpid(), pid_attacker[i]); kill(pid_attacker[i], SIGKILL); } gettimeofday(&tv2, NULL); char time_to_char[20]; printf ("\nTotal time = %f seconds\n", (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 + (double) (tv2.tv_sec - tv1.tv_sec)); sprintf(time_to_char, "%f\n", (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 + (double) (tv2.tv_sec - tv1.tv_sec)); // Stopping and reading for Gnuplot if((ret = PAPI_stop(PAPI_EventSet, papi_values))!= PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't stop the counters %s\n", PAPI_strerror(ret)); exit(17); } if((ret = PAPI_stop(scheduler_eventset, &scheduler_value))!= PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't stop the counters %s\n", PAPI_strerror(ret)); exit(17); } if((ret = PAPI_read(PAPI_EventSet, papi_values)) != PAPI_OK){ fprintf(stderr, "PAPI error : Couldn't read the values %s\n", PAPI_strerror(ret)); exit(18); } // Printing and writting for Gnuplot print_counters(papi_values); write_miss_values(1, nb_attackers, papi_values); // Writting the time for Gnuplot int fic_time; char fic_name[50]; switch(atoi(argv[2])){ case 0: strcpy(fic_name, "plot/mesures_execution_0_scheduler.data"); break; case 1: strcpy(fic_name, "plot/mesures_execution_1_scheduler.data"); break; case 2: strcpy(fic_name, "plot/mesures_execution_2_scheduler.data"); break; default: strcpy(fic_name, "plot/mesures_execution.data"); break; } if ((fic_time = open(fic_name, O_RDWR | O_APPEND))==-1){ perror("Open error on fic_time\n"); exit(19); } if (write(fic_time, time_to_char, strlen(time_to_char))==0){ fprintf(stderr, "Write exec_time error\n"); exit(20); } // Cleaning event sets if((ret=PAPI_cleanup_eventset(PAPI_EventSet))!=PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't clean the Event Set %s\n", PAPI_strerror(ret)); exit(19); } if((ret=PAPI_cleanup_eventset(scheduler_eventset))!=PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't clean the Event Set %s\n", PAPI_strerror(ret)); exit(19); } if((ret=PAPI_destroy_eventset(&PAPI_EventSet))!=PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't destroy the Event Set %s\n", PAPI_strerror(ret)); exit(20); } if((ret=PAPI_destroy_eventset(&scheduler_eventset))!=PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't destroy the Event Set %s\n", PAPI_strerror(ret)); exit(20); } } return EXIT_SUCCESS; }
// Print an event. void SimpleThresholdPolicy::print_event(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level) { bool inlinee_event = mh() != imh(); ttyLocker tty_lock; tty->print("%lf: [", os::elapsedTime()); switch(type) { case CALL: tty->print("call"); break; case LOOP: tty->print("loop"); break; case COMPILE: tty->print("compile"); break; case REMOVE_FROM_QUEUE: tty->print("remove-from-queue"); break; case UPDATE_IN_QUEUE: tty->print("update-in-queue"); break; case REPROFILE: tty->print("reprofile"); break; case MAKE_NOT_ENTRANT: tty->print("make-not-entrant"); break; default: tty->print("unknown"); } tty->print(" level=%d ", level); ResourceMark rm; char *method_name = mh->name_and_sig_as_C_string(); tty->print("[%s", method_name); if (inlinee_event) { char *inlinee_name = imh->name_and_sig_as_C_string(); tty->print(" [%s]] ", inlinee_name); } else tty->print("] "); tty->print("@%d queues=%d,%d", bci, CompileBroker::queue_size(CompLevel_full_profile), CompileBroker::queue_size(CompLevel_full_optimization)); print_specific(type, mh, imh, bci, level); if (type != COMPILE) { print_counters("", mh); if (inlinee_event) { print_counters("inlinee ", imh); } tty->print(" compilable="); bool need_comma = false; if (!mh->is_not_compilable(CompLevel_full_profile)) { tty->print("c1"); need_comma = true; } if (!mh->is_not_osr_compilable(CompLevel_full_profile)) { if (need_comma) tty->print(","); tty->print("c1-osr"); need_comma = true; } if (!mh->is_not_compilable(CompLevel_full_optimization)) { if (need_comma) tty->print(","); tty->print("c2"); need_comma = true; } if (!mh->is_not_osr_compilable(CompLevel_full_optimization)) { if (need_comma) tty->print(","); tty->print("c2-osr"); } tty->print(" status="); if (mh->queued_for_compilation()) { tty->print("in-queue"); } else tty->print("idle"); } tty->print_cr("]"); }
//---------------------------------------------------------------------- const char* parse_args(int argc, const char** argv, int parseonly, struct log2mem_handle * handle) { int i = 1; const char* filename = 0; int defaultshow = 1; enum showbits { eSummary = 0x01, eCounters = 0x02, eRows = 0x04, eVars = 0x08 }; int toshow = 0; for (;i < argc; i++) { if ( strcmp(argv[i], "-h")==0 || strcmp(argv[i],"--help")==0 ) help(); else if (strcmp(argv[i], "-s")==0) { toshow |= eSummary; } else if (strcmp(argv[i], "-c")==0) { toshow |= eCounters; } else if (strcmp(argv[i], "-r")==0) { toshow |= eRows; } else if (strcmp(argv[i], "-v")==0) { toshow |= eVars; } else if (strcmp(argv[i], "-a")==0) { toshow |= ~eSummary; } else if (strcmp(argv[i], "-F")==0) { if (++i >= argc) die("missing argument to -F", NULL); g_delim = argv[i]; g_showdelim = 1; } else if (strcmp(argv[i], "-z")==0) { g_showdelim = 0; } else if (strcmp(argv[i], "-t")==0) { g_terse = 1; } else if (strcmp(argv[i], "--version")==0) { printf("log2mem version: " PACKAGE_VERSION "\n"); exit(1); } else if (strncmp(argv[i], OPT_DOUBLE, strlen(OPT_DOUBLE))==0) { set_var_double(argc, argv, &i, handle); defaultshow = 0; } else if (strncmp(argv[i], OPT_INT, strlen(OPT_INT))==0) { set_var_int(argc, argv, &i, handle); defaultshow = 0; } else if (strncmp(argv[i], OPT_STRING, strlen(OPT_STRING))==0) { set_var_string(argc, argv, &i, handle); defaultshow = 0; } else if ((strncmp(argv[i], "--",2)==0) && strlen(argv[i])>2 ) { set_var_by_name(argc, argv, &i, handle); defaultshow = 0; } else { if (filename == 0) filename = argv[i]; else { die("unexpected argument: ", argv[i]); } } } if (defaultshow && !toshow) toshow = 0xFFFF; if (!parseonly) { //if (toshow & eSummary) print_summary(handle); if (toshow & eRows) print_rows(handle); if (toshow & eCounters) print_counters(handle); if (toshow & eVars) print_vars(handle); } return filename; }