Example #1
0
int main()
{
    // try load up 'processes_q5.txt'
    FILE* process_list =  fopen(FPATH_PROCESSES_Q5, "r");
    if(!process_list)
    {
        fprintf(stderr, "Error: Failed to load '%s'\n", FPATH_PROCESSES_Q5);
        return 1;
    }
    
    // read in stuff from processes
    node_t* head = NULL;
    load_processes(process_list, &head);
    
    // close the process list
    fclose(process_list);

    // run hi priority then lower-priority processes
    run_processes(&head, 0);
    run_processes(&head, -1);


    // pop any remaining nodes
    while(head)
    {
        pop(&head);
    }

    // run; now you're done.
    return 0;
}
Example #2
0
/* lock a byte range in a open file */
int main(int argc, char *argv[])
{
	int nprocs, i;
	char *tname = "ALL";
#define NREPEATS 10
	struct {
		const char *name;
		void *(*fn)(int );
	} tests[] = {
		{"noop", test_noop},
		{"malloc", test_malloc},
		{"setreuid", test_setreuid},
		{"readwrite", test_readwrite},
		{"stat", test_stat},
		{"fstat", test_fstat},
		{"dir", test_dir},
		{"dirsingle", test_dirsingle},
		{"create", test_create},
		{"lock", test_lock},
		{NULL, NULL}
	};

	if (argc <= 1) {
		printf("thread_perf NPROCS\n");
		exit(1);
	}

	nprocs = atoi(argv[1]);

	if (argc > 2) {
		tname = argv[2];
	}

	id_data = calloc(nprocs, sizeof(*id_data));
	if (!id_data) {
		exit(1);
	}

#ifndef NO_THREADS
	printf("NOTE! for accurate process results please compile with -DNO_THREADS and don't link to -lpthread\n\n");
#endif

	for (i=0;i<nprocs;i++) {
		char s[30];
		sprintf(s, "testd_%d", i);
		id_data[i].dname = strdup(s);

		sprintf(s, "%s/test.dat", id_data[i].dname);
		id_data[i].fname = strdup(s);

		rmdir(id_data[i].dname);
		if (mkdir(id_data[i].dname, 0777) != 0) {
			fprintf(stderr, "Failed to create %s\n", id_data[i].dname);
			exit(1);
		}

		unlink(id_data[i].fname);
	}

	for (i=0;tests[i].name;i++) {
		double t_threads[NREPEATS];
		double t_processes[NREPEATS];
		int j;

		if (strcasecmp(tname, "ALL") && strcasecmp(tests[i].name, tname)) {
			continue;
		}

		printf("Running test '%s' with %d tasks\n", tests[i].name, nprocs);

		for (j=0;j<NREPEATS;j++) {
#ifndef NO_THREADS
			t_threads[j]   = run_threads(nprocs, tests[i].fn);
#endif
			t_processes[j] = run_processes(nprocs, tests[i].fn);
		}
#ifndef NO_THREADS
		show_result("Threads  ", t_threads, NREPEATS);
#endif
		show_result("Processes", t_processes, NREPEATS);

		printf("\n");
		fflush(stdout);
	}

	for (i=0;i<nprocs;i++) {
		if (rmdir(id_data[i].dname) != 0) {
			fprintf(stderr, "Failed to delete %s\n", id_data[i].dname);
			exit(1);
		}
	}

	for (i=0;i<nprocs;i++) {
		free(id_data[i].dname);
		free(id_data[i].fname);
	}
	free(id_data);

	return 0;
}