/* * Tasks (read, write, load) * by matsu@igel.co.jp */ #include #include #include #include #include #include #include #include #define MAXNAMELEN 32 #define MAXTHREADS 32 #define PROC_CURRENTIME "/proc/currentime" #define PROC_UPTIME "/proc/uptime" #define N_REP 10000 #define SIGNAL_INTERVAL 16 /* ms */ struct irqfile { unsigned long irq; char name[MAXNAMELEN]; }; struct timeval tv0[N_REP], tv1[N_REP], tv2[N_REP], tv_s, tv_e; static void irqhandle(void *arg) { struct irqfile *irqf = (struct irqfile *)arg; int fd; volatile int i; static float waste; if ((fd = open(irqf->name, O_RDONLY)) < 0) { perror("open proc file"); pthread_exit(NULL); } fprintf(stderr, "irqhandle: waiting for irq...\n"); for(i=0; iname, O_WRONLY)) < 0) { perror("open proc file"); pthread_exit(NULL); } fprintf(stderr, "irqgen: waiting for seconds...\n"); sleep(5); fprintf(stderr, "irqgen: go!\n"); /* send irq signal*/ gettimeofday(&tv_s, NULL); for (i=0; i 4)) { fprintf(stderr, "Usage: %s irq_no num_of_hamper " "[priority_for_irqhandler]\n", argv[0]); return -1; } irqf = (struct irqfile *)malloc(sizeof(struct irqfile)); if (!irqf) return -1; irqf->irq = strtoul(argv[1], NULL, 0); memset(irqf->name, 0, MAXNAMELEN); sprintf(irqf->name, "/proc/irqhook/%d", irqf->irq); pthread_attr_init(&thattr); /* user-level irq handler thread */ pthread_create(&th[0], NULL, (void (*))irqhandle, (void *)irqf); if ((argc == 4) && ((sp.sched_priority = strtoul(argv[3], NULL, 0)) > 0)) { if (!pthread_setschedparam(th[0], SCHED_RR, &sp)); } /* hamper threads */ ts.tv_sec = 0; ts.tv_nsec = 3000; hams = strtoul(argv[2], NULL, 0); for (i=2; i<(hams + 2); i++) { nanosleep(&ts, NULL); pthread_create(&th[i], NULL, (void (*))cpuhamper, NULL); } /* virtual irq generator thread */ pthread_create(&th[1], NULL, (void (*))irqgen, (void *)irqf); if ((argc == 4) && ((sp.sched_priority = strtoul(argv[3], NULL, 0) + 1) > 0)) { if (!pthread_setschedparam(th[1], SCHED_RR, &sp)); } pthread_join(th[0], NULL); pthread_join(th[1], NULL); for (i=0; i