Example #1
0
void verify_network_conf() {
	dmesg("verify_network_conf:\n", 0);
	verify_node_conf();
	verify_pipe_conf();
	verify_comp_conf();
	dmesg("verify_network_conf:\tPassed\n", 0);
}
Example #2
0
void verify_node_conf() {
	dmesg("\tverify_node_conf:\n", 0);
	printf("\t[Node Configuration]\n");
	for (int j = 0; j < net.nodes; j++) {
		printf("\tNode %d at %p\n", j, &net.node[j]);
		if (net.node[j].type == 1) printf("\tPressure Type\n");
		else printf("\tTransport Type\n");
		printf("\tCompressors:\t%d\n", net.node[j].ncomp);
		if (net.node[j].ncomp) {
			printf("\tCompressor List:");
			for (int k = 0; k < net.node[j].ncomp; k++) {
				printf("\t%p", net.node[j].comp[k]);
			}
			printf("\n");
		}
		printf("\tIncoming pipes:\t%d\n", net.node[j].nleft);
		if (net.node[j].nleft) {
			printf("\tIncoming Pipe List:");
			for (int k = 0; k < net.node[j].nleft; k++) {
				printf("\t%p", net.node[j].left[k]);
			}
			printf("\n");
		}
		printf("\tOutgoing pipes:\t%d\n", net.node[j].nright);
		if (net.node[j].nright) {
			printf("\tOutgoing Pipe List:");
			for (int k = 0; k < net.node[j].nright; k++) {
				printf("\t%p", net.node[j].right[k]);
			}
			printf("\n");
		}
		printf("\n");
	}
	dmesg("\tverify_node_conf:\tPassed\n", 0);
}
Example #3
0
void verify_comp_conf() {
	dmesg("\tverify_comp_conf:\n", 0);
	printf("\t[Compressor Configuration]\n");
	for (int j = 0; j < net.comps; j++) {
		printf("\tCompressor %d at %p\n", j, &net.comp[j]);
		printf("\tSource Node:\t%p\n", net.comp[j].loc);
		printf("\tBoost Pipe:\t%p\n\n", net.comp[j].dest);
	}
	dmesg("\tverify_comp_conf:\tPassed\n", 0);
}
Example #4
0
void verify_pipe_conf() {
	dmesg("\tverify_pipe_conf:\n", 0);
	printf("\t[Pipe Configuration]\n");
	for (int j = 0; j < net.pipes; j++) {
		printf("\tPipe %d at %p\n", j, &net.pipe[j]);
		printf("\tSource Node:\t\t%p\n", net.pipe[j].left);
		printf("\tDestination Node:\t%p\n", net.pipe[j].right);
		printf("\tCompressor:\t\t%p\n", net.pipe[j].cmp);
		printf("\tLength:\t\t\t%e\n", net.pipe[j].len*1e-3);
		printf("\tWidth:\t\t\t%e\n\n", net.pipe[j].wid);
	}
	dmesg("\tverify_pipe_conf:\tPassed\n", 0);
}
Example #5
0
static void on_scan_ready(void *arg, STATUS status)
{
	if (status != OK) {
		dmesg("Scan failed");
		return;
	}

	struct bss_info *bss = (struct bss_info *)arg;
	// FIXME: would be much better to only send one message
	while (bss != NULL) {
		bss->ssid[sizeof(bss->ssid) - 1] = '\0';
		dmesg("ssid=%s channel=%d", bss->ssid, bss->channel);
		bss = bss->next.stqe_next;
	}
}
Example #6
0
static void __exit upmt_fini(void) {

	if(KA_TIMER == 1) ka_timer_unregister();
	upmt_genl_unregister();
	xt_UPMT_ex_exit();
	upmt_ph_unregister_all();
	upmt_dev_unregister();

	//write_lock_irqsave(&bul_mutex, flag);
	pdft_erase();

	 // Now this unregisters every packet handler instead of the netfilter hook (Sander)
	paft_erase();
	tunt_erase();
	tsa_erase();
	spl_erase();
	mdl_erase();
	//write_unlock_irqrestore(&bul_mutex, flag);

#ifdef UPMT_S
	upmt_s_fini();
#endif

	dmesg(unload_banner);
}
Example #7
0
void init_kbd()
{
    mode = 0;
    leds = 2;
    setleds();
    dmesg("Init keyboard driver completed!");
}
Example #8
0
void upmt_s_fini(void) {
	nf_unregister_hook(hook_out);
	nf_unregister_hook(hook_in);
	nf_unregister_hook(hook_fwd);

	dmesg("UPMT-S extension unloaded");
}
Example #9
0
int irq_ack( struct thread *t, int irq, int status )
{
	acquire_spinlock( &irq_lock );

	dmesg("%!ACK with status %i for %i\n", status, irq );

		if ( status == 0 )
		{
			unmask_irq( irq );
			release_spinlock( &irq_lock );
			return 0;
		}

	dmesg("%!Unhandled IRQ %i\n", irq );
	release_spinlock( &irq_lock );
	return 0;
}
Example #10
0
void verify_input_conf() {
	dmesg("verify_input_conf:\n", 0);
	printf("\t[Input Configuration]\n");
	printf("\tname=\t%s\n", par.name);
	printf("\tstep=\t%.8e\n", par.dx);
	printf("\tskip=\t%d\n", par.skip);
	printf("\ttmax=\t%.8e\n", par.tmax/3600.);
	printf("\tsounds=\t%.8e\n", par.sound);
	printf("\tDWdiss=\t%.8e\n", par.friction);
	printf("\tinterp=\t%s\n", par.intmethod);
	printf("\t[Simulation Configuration]\n");
	printf("\tTime step\t%.6f secs\n", par.dt); 
	printf("\tOutput every\t%.2f secs\n", par.skip*par.dt);
	printf("\tTotal steps\t%u\n", par.nsteps);
	printf("\tGSL Interp:\t%s\n", par.intmethod);
	dmesg("verify_input_conf:\tPassed\n", 0);
}
Example #11
0
void init_semaphores()
{
	int i;

	dmesg( "initialising the semaphore structures.\n");

	for ( i = 0; i < GLOBAL_SEM_COUNT; i++)
		global_sems[i].sem_id = -1;

}
Example #12
0
void on_mqtt_data(uint32_t *args, const char *topic, uint32_t topic_len,
		  const char *data, uint32_t data_len)
{
	char cmd[256];

	if (data_len < sizeof(cmd)) {
		os_memcpy(cmd, data, data_len);
		cmd[data_len] = '\0';

		/* echo back the message */
		dmesg(cmd);

		if (strcmp("SCAN", cmd) == 0) {
			wifi_station_scan(NULL, on_scan_ready);
		} else if (strcmp("ADC_READ", cmd) == 0) {
			uint16 adc_in = system_adc_read();
			dmesg("adc_in=%hu", (unsigned short)adc_in);
		}
	}
}
Example #13
0
int irq_handler( int irq )
{
	acquire_spinlock( &irq_lock );
	mask_irq( irq );

	dmesg("%!IRQ %i occurred on %i\n", irq, CPUID );
	
		if ( handlers[irq] != NULL )
		{
			queue( handlers[irq] );
		}
	

	ack_irq( irq );
	release_spinlock( &irq_lock );
	return 0;
}
Example #14
0
int init_random()
{
   int i;
   int opp_pos;
   int tmp;
   int tock;

     dmesg("initialiasing the random number pools.\n" );


     tock = (int)epoch_seconds();
    
     random_index = tock % RANDOM_POOL_SIZE;
     random_bit = 0;
    
	// Let's do a whole bunch of rubbish here with uninitialised
	// data and hope it's random-ish.
     for ( i = 0; i < RANDOM_POOL_SIZE; i++ )
      {
		 opp_pos = RANDOM_POOL_SIZE - i - 1;
         random_pool[i] |= (tock % 16) << ( tock % 32 );
      	 random_pool[i] += ~tock;
		 tock += (tock << ( i % 5 ));	
      }
   
	// Now let's mess things up a little.
     for ( i = 0; i < RANDOM_POOL_SIZE; i++ )
      {
		 opp_pos = RANDOM_POOL_SIZE - i - 1;
     
     	 tmp  = random_pool[i] % random_pool[opp_pos];
		 tmp ^= ~tock;
     
     	 if ( ( tmp % 2 ) == 0 )
        	 random_pool[i] += ( tock >> ( i % 8 ) );
		 else	 
        	 random_pool[i] += ( tock << ( i % 8 ) );
	 
		 tock += (tock << ( i % 5 )) + random_pool[i];
      }
Example #15
0
int upmt_s_init(void) {
	int err = 0;

	dmesg("UPMT-S extension initialized");

	//UPMT-S hook for OUTgoing packets
	hook_out = kzalloc(sizeof(struct nf_hook_ops), GFP_KERNEL);
	
	hook_out->hook 		= upmt_set_app_flow;
	hook_out->pf 		= PF_INET;
	hook_out->hooknum	= NF_INET_POST_ROUTING;
	hook_out->priority	= NF_IP_PRI_FIRST;
	
	if ((err = nf_register_hook(hook_out)))
		kfree(hook_out);

	//UPMT-S hook for INcoming packets - for local processes
	hook_in = kzalloc(sizeof(struct nf_hook_ops), GFP_KERNEL);
	
	hook_in->hook 		= upmt_update_paft;
	hook_in->pf 		= PF_INET;
	hook_in->hooknum	= NF_INET_LOCAL_IN;
	hook_in->priority	= NF_IP_PRI_FIRST;
	
	if ((err = nf_register_hook(hook_in)))
		kfree(hook_in);

	//UPMT-S hook for INcoming packets - to forward
	hook_fwd = kzalloc(sizeof(struct nf_hook_ops), GFP_KERNEL);
	
	hook_fwd->hook 		= upmt_update_paft;
	hook_fwd->pf 		= PF_INET;
	hook_fwd->hooknum	= NF_INET_FORWARD;
	hook_fwd->priority	= NF_IP_PRI_FIRST;
	
	if ((err = nf_register_hook(hook_fwd)))
		kfree(hook_fwd);

	return err;
}
Example #16
0
void ICACHE_FLASH_ATTR user_init()
{
	/* set baud rate */
	uart_div_modify(0, UART_CLK_FREQ / 115200);

	wifi_set_opmode(1); /* station mode */
	struct station_config config;
	os_bzero(&config, sizeof(config));
	strncpy((char *)config.ssid, WIFI_SSID, sizeof(config.ssid));
	strncpy((char *)config.password, WIFI_PASS, sizeof(config.password));
	wifi_station_set_config(&config);

	MQTT_InitConnection(&mqtt_client, MQTT_HOST, MQTT_PORT, 0);
	MQTT_InitClient(&mqtt_client, MQTT_CLIENT_ID, MQTT_USER, MQTT_PASS,
			MQTT_KEEPALIVE, MQTT_CLEAN_SESSION);
	MQTT_OnConnected(&mqtt_client, on_mqtt_connected);
	MQTT_OnData(&mqtt_client, on_mqtt_data);

	dmesg("Starting up");

	/* setup timer (1000ms, repeating) */
	os_timer_setfn(&some_timer, (os_timer_func_t *)on_timer, NULL);
	os_timer_arm(&some_timer, 1000, 1);
}
Example #17
0
static void on_mqtt_connected(uint32_t *args)
{
	dmesg("Hello, world!");
	MQTT_InitLWT(&mqtt_client, TOPIC_DMESG, "Goodbye, cruel world!", 0, 1);
	MQTT_Subscribe(&mqtt_client, TOPIC_CONTROL, 0);
}
Example #18
0
static int __init upmt_init(void) {
	upmtns=current->nsproxy; // Namespace 'imprinting' for the current module (Sander)
	an_mark = 0;
	INIT_LIST_HEAD(&(registered_pt.list)); // Inizialization for Packet Handler/Type list (Sander)
	init_headrooms();
	set_ka_values();
	if (mdl_create())			goto fail_mdl_create;
	if (spl_create())			goto fail_spl_create;
	if (tsa_create())			goto fail_tsa_create;
	if (tunt_create())			goto fail_tunt_create;
	if (paft_create())			goto fail_paft_create;
	if (pdft_create())			goto fail_pdft_create;
//	if (upmt_nf_register())			goto fail_upmt_nf_register; // pack handler is inserted when bringing a dev under upmt control (Sander)
	if (upmt_dev_register())		goto fail_upmt_dev_register;
	//if (upmt_genl_register(FAM))		goto fail_upmt_genl_register;
	if (upmt_genl_register())		goto fail_upmt_genl_register;


#ifdef UPMT_S
	//TODO check for errors..
	if (upmt_s_init()) {
		dmesge("UPMT-S init error");
		goto fail_upmt_s_init;
	}
#endif

	xt_UPMT_ex_init();
	if(KA_TIMER == 1) ka_timer_register();

	dmesg(load_banner);
	dmesg(KERN_ALERT);

	printk("UPMT_MODULE - AN variable value: %d\n", AN);

	return 0;

#ifdef UPMT_S
fail_upmt_s_init:
	upmt_genl_unregister();
#endif

fail_pdft_create:
	//tunt_erase();
	
fail_upmt_genl_register:
	upmt_dev_unregister();

//fail_upmt_dev_register:
//	upmt_nf_unregister();
	
fail_upmt_dev_register:
	paft_erase();

//fail_upmt_nf_register:
//	paft_erase();

fail_paft_create:
	tunt_erase();
	
fail_tunt_create:
	tsa_erase();

fail_tsa_create:
	spl_erase();

fail_spl_create:
	mdl_erase();

fail_mdl_create:
	return -1;
}
Example #19
0
int
main(int argc, char *argv[])
{
        int    i, j, fd, rc, nops, lastOps;
        int ag_ops = 0;
        double ag_interval = 0;
        double ag_rate = 0;
        double rate, avg_rate, effective_rate;
        double startTime, curTime, lastTime, interval;
        time_t timestamp;
        char * file;

        rc = MPI_Init(&argc, &argv);
        if (rc != MPI_SUCCESS)
                fatal(myrank, "MPI_Init failed: %d\n", rc);

        rc = MPI_Comm_size(MPI_COMM_WORLD, &nthreads);
        if (rc != MPI_SUCCESS)
                fatal(myrank, "MPI_Comm_size failed: %d\n", rc);

        rc = MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
        if (rc != MPI_SUCCESS)
                fatal(myrank, "MPI_Comm_rank failed: %d\n", rc);

        process_args(argc, argv);

        timestamp = time(0);
        if ((myrank == 0) || debug) {
        	printf("%d: %s starting at %s",
		       myrank, hostname, ctime(&timestamp));
	}

        /* if we're not measuring creation rates then precreate
         * the files we're operating on. */
        if ((mode != CREATE) && (mode != MKNOD) && !ignore &&
            (mode != UNLINK || recreate)) {
                /* create the files in reverse order. When we encounter
                 * a file that already exists, assume the remainder of 
                 * the files exist to save time. The timed performance
                 * test scripts make use of this behavior. */
                for (i = end, j = 0; i >= begin; i -= dirthreads) {
                        sprintf(filename, filefmt, i);
                        fd = open(filename, openflags, 0644);
                        if (fd < 0) {
                                if (errno == EEXIST)
                                        break;
                                rc = errno;
                                fatal(myrank, "precreate open(%s) error: %s\n",
                                      filename, strerror(rc));
                        }
                        j++;
                        close(fd);
                }
                dmesg("%d: %s pre-created %d files.\n",myrank,hostname,j);

                rc = MPI_Barrier(MPI_COMM_WORLD);
                if (rc != MPI_SUCCESS)
                        fatal(myrank, "prep MPI_Barrier failed: %d\n", rc);
        }

        if (order == READDIR) {
                directory = opendir(dir);
                if (directory == NULL) {
                        rc = errno;
                        fatal(myrank, "opendir(%s) error: %s\n",
                              dir, strerror(rc));
                }

                timestamp = time(0);
                j = random() % nfiles;
                dmesg("%d: %s initializing dir offset %u: %s",
                      myrank, hostname, j, ctime(&timestamp));

                for (i = 0; i <= j; i++) {
                        if ((dir_entry = readdir(directory)) == NULL) {
                                fatal(myrank, "could not read entry number %d "
                                      "in directory %s.\n", i, dir);
                        }
                }

                timestamp = time(0);
                dmesg("%d: index %d, filename %s, offset %ld: "
                      "%s initialization complete: %s",
                      myrank, i, dir_entry->d_name, telldir(directory),
                      hostname, ctime(&timestamp));
        }

        if (seconds) {
                act.sa_handler = sigalrm_handler;
                (void)sigemptyset(&act.sa_mask);
                act.sa_flags = 0;
                sigaction(SIGALRM, &act, NULL);
                alarm(seconds);
        }

        rc = MPI_Barrier(MPI_COMM_WORLD);
        if (rc != MPI_SUCCESS)
                fatal(myrank, "prep MPI_Barrier failed: %d\n", rc);

        startTime = lastTime = MPI_Wtime();
        nops = lastOps = 0;

        switch (mode) {
	case CREATE:
		for (; begin <= end && !alarm_caught; begin += dirthreads) {
			snprintf(filename, sizeof(filename), filefmt, begin);
			fd = open(filename, openflags, 0644);
			if (fd < 0) {
				rc = errno;
				if (rc == EINTR && alarm_caught)
					break;
				fatal(myrank, "open(%s) error: %s\n",
				      filename, strerror(rc));
			}

			if (with_xattr) {
				rc = fsetxattr(fd, xattrname, xattrbuf,
					       xattrlen, XATTR_CREATE);
				if (rc) {
					rc = errno;
					if (rc == EINTR && alarm_caught)
						break;
					fatal(myrank,
					      "setxattr(%s) error: %s\n",
					      filename, strerror(rc));
				}
			}
			if (smallwrite) {
				rc = write(fd, xattrbuf, xattrlen);
				if (rc < 0) {
					rc = errno;
					if (rc == EINTR && alarm_caught)
						break;
					fatal(myrank,
					      "write(%s) error: %s\n",
					      filename, strerror(rc));
				}
			}

			close(fd);
			nops++;
			DISPLAY_PROGRESS();
		}

		dmesg("%d: created %d files, last file '%s'.\n",
		      myrank, nops, filename);
		break;
#ifdef HAVE_MDC_LOOKUP
        case LOOKUP:
                fd = open(dir, O_RDONLY);
                if (fd < 0) {
                        fatal(myrank, "open(dir == '%s') error: %s\n",
                              dir, strerror(errno));
                }

                for (; nops < iters && !alarm_caught;) {
                        char *filename = next_file();
                        rc = llapi_file_lookup(fd, filename);
                        if (rc < 0) {
                                if (((rc = errno) == EINTR) && alarm_caught)
                                        break;
                                fatal(myrank, "llapi_file_lookup(%s) "
                                      "error: %s\n", filename, strerror(rc));
                        }

                        nops++;
                        DISPLAY_PROGRESS();
                }
                break;
#endif
	case MKNOD:
		for (; begin <= end && !alarm_caught; begin += dirthreads) {
			snprintf(filename, sizeof(filename), filefmt, begin);
			rc = mknod(filename, S_IFREG | 0644, 0);
			if (rc) {
				rc = errno;
				if (rc == EINTR && alarm_caught)
					break;
				fatal(myrank, "mknod(%s) error: %s\n",
				      filename, strerror(rc));
			}

			if (with_xattr) {
				rc = setxattr(filename, xattrname, xattrbuf,
					      xattrlen, XATTR_CREATE);
				if (rc) {
					rc = errno;
					if (rc == EINTR && alarm_caught)
						break;
					fatal(myrank,
					      "setxattr(%s) error: %s\n",
					      filename, strerror(rc));
				}
			}

			nops++;
			DISPLAY_PROGRESS();
		}
		break;
        case OPEN:
                for (; nops < iters && !alarm_caught;) {
                        file = next_file();
                        if ((fd = open(file, openflags, 0644)) < 0) {
                                if (((rc = errno) == EINTR) && alarm_caught)
                                        break;
                                fatal(myrank, "open(%s) error: %s\n",
                                      file, strerror(rc));
                        }

                        close(fd);

                        nops++;
                        DISPLAY_PROGRESS();
                }
                break;
        case STAT:
                for (; begin <= end && !alarm_caught; begin += dirthreads) {
                        sprintf(filename, filefmt, begin);
                        rc = stat(filename, &statbuf);
                        if (rc) {
                                if (((rc = errno) == EINTR) && alarm_caught)
                                        break;
                                if (((rc = errno) == ENOENT) && ignore)
                                        continue;
                                fatal(myrank, "stat(%s) error: %s\n",
                                      filename, strerror(rc));
                        }

                        nops++;
                        DISPLAY_PROGRESS();
                }
                break;
        case UNLINK:
                for (; begin <= end && !alarm_caught; begin += dirthreads) {
                        sprintf(filename, filefmt, begin);
                        rc = unlink(filename);
                        if (rc) {
                                if (((rc = errno) == EINTR) && alarm_caught)
                                        break;
                                if ((rc = errno) == ENOENT) {
                                        if (ignore)
                                                continue;
                                        /* no more files to unlink */
                                        break;
                                }
                                fatal(myrank, "unlink(%s) error: %s\n",
                                      filename, strerror(rc));
                        }

                        nops++;
                        DISPLAY_PROGRESS();
                }
                break;
	case SETXATTR:
		for (; begin <= end && !alarm_caught; begin += dirthreads) {
			snprintf(filename, sizeof(filename), filefmt, begin);
			rc = setxattr(filename, xattrname, xattrbuf, xattrlen,
				      XATTR_CREATE);
			if (rc) {
				rc = errno;
				if (rc == EINTR && alarm_caught)
					break;
				if (rc == ENOENT && ignore)
					continue;
				fatal(myrank, "setxattr(%s) error: %s\n",
				      filename, strerror(rc));
			}

			nops++;
			DISPLAY_PROGRESS();
		}
		break;
        }

        rc = MPI_Barrier(MPI_COMM_WORLD);
        if (rc != MPI_SUCCESS)
               fatal(myrank, "prep MPI_Barrier failed: %d\n", rc);
        curTime = MPI_Wtime();
        interval = curTime - startTime;
        rate = (double) (nops) / interval;

        rc = MPI_Reduce(&nops, &ag_ops, 1, MPI_INT, MPI_SUM, 0,
                        MPI_COMM_WORLD);
        if (rc != MPI_SUCCESS) {
                fatal(myrank, "Failure in MPI_Reduce of total ops.\n");
        }

        rc = MPI_Reduce(&interval, &ag_interval, 1, MPI_DOUBLE, MPI_SUM, 0,
                        MPI_COMM_WORLD);
        if (rc != MPI_SUCCESS) {
                fatal(myrank, "Failure in MPI_Reduce of total interval.\n");
        }

        rc = MPI_Reduce(&rate, &ag_rate, 1, MPI_DOUBLE, MPI_SUM, 0,
                        MPI_COMM_WORLD);
        if (rc != MPI_SUCCESS) {
                fatal(myrank, "Failure in MPI_Reduce of aggregated rate.\n");
        }

        if (myrank == 0) {
                curTime = MPI_Wtime();
                interval = curTime - startTime;
                effective_rate = (double) ag_ops / interval;
                avg_rate = (double) ag_ops / ag_interval;

                printf("Rate: %.2f eff %.2f aggr %.2f avg client %ss/sec "
                       "(total: %d threads %d %ss %d dirs %d threads/dir %.2f secs)\n",
                       effective_rate, ag_rate, avg_rate, cmd, nthreads, ag_ops,
                       cmd, ndirs, dirthreads, interval);
                if (mode == UNLINK && !recreate && !ignore && ag_ops != nfiles)
                        printf("Warning: only unlinked %d files instead of %d"
                               "\n", ag_ops, nfiles);
        }

        if (recreate) {
                for (begin = beginsave; begin <= end; begin += dirthreads) {
                        sprintf(filename, filefmt, begin);
                        if ((fd = open(filename, openflags, 0644)) < 0) {
                                rc = errno;
				if (rc == EEXIST)
					break;
                                fatal(myrank, "recreate open(%s) error: %s\n",
                                      filename, strerror(rc));
                        }

                        close(fd);
                }
        }

        timestamp = time(0);
        if ((myrank == 0) || debug) {
        	printf("%d: %s finished at %s",
		       myrank, hostname, ctime(&timestamp));
	}

        MPI_Finalize();
        return(0);
}
Example #20
0
static void
process_args(int argc, char *argv[])
{
        char   *cp, *endptr;
        int    i, index, offset, tmpend, rc;
        char   tmp[16];
        FILE * seed_file;
        struct option *opt;

        setbuf(stdout, 0);
        setbuf(stderr, 0);
        prog = basename(argv[0]);
        strcpy(filefmt, "f%d");
        gethostname(hostname, sizeof(hostname));

        /* auto create shortOpts rather than maintaining a static string. */
        for (opt = longOpts, cp = shortOpts; opt->name != NULL; opt++, cp++) {
                *cp = opt->val;
                if (opt->has_arg)
                        *++cp = ':';
        }

        while ((rc = getopt_long(argc,argv, shortOpts, longOpts,&index)) != -1) {
                switch (rc) {
                case OPEN:
                        openflags &= ~(O_CREAT|O_EXCL);
                case CREATE:
#ifdef HAVE_MDC_LOOKUP
                case LOOKUP:
#endif
                case MKNOD:
                case STAT:
                case UNLINK:
                        if (cmd != NULL) {
                                fatal(0, "Invalid - more than one operation "
                                           "specified: --%s\n",
                                        longOpts[index].name);
                        }
                        mode = rc;
                        cmd = (char *)longOpts[index].name;
                        break;
                case NOEXCL:
                        if (mode != CREATE && mode != MKNOD) {
                                usage(stderr, "--noexcl only applies to "
                                              "--create or --mknod.\n");
                        }
                        openflags &= ~O_EXCL;
                        break;
                case RECREATE:
                        if (mode != UNLINK) {
                                usage(stderr, "--recreate only makes sense"
                                              "with --unlink.\n");
                        }
                        recreate++;
                        break;
		case SETXATTR:
			if (cmd == NULL) {
				mode = SETXATTR;
				cmd = (char *)longOpts[index].name;
			} else if (mode == CREATE || mode == MKNOD) {
				with_xattr = true;
			} else {
				usage(stderr, "--setxattr only makes sense "
				      "with --create, --mknod or alone.\n");
			}
			break;
		case SMALLWRITE:
			if (mode != CREATE)
				usage(stderr, "--smallwrite only applies to "
					      "--create.\n");
			smallwrite = true;
			break;
                case BEGIN:
                        begin = strtol(optarg, &endptr, 0);
                        if ((*endptr != 0) || (begin < 0)) {
                                fatal(0, "Invalid --start value.\n");
                        }
                        break;
                case ITERS:
                        iters = strtol(optarg, &endptr, 0);
                        if ((*endptr != 0) || (iters <= 0)) {
                                fatal(0, "Invalid --iters value.\n");
                        }
                        if (mode != LOOKUP && mode != OPEN) {
                                usage(stderr, "--iters only makes sense with "
                                              "--lookup or --open.\n");
                        }
                        break;
                case TIME:
                        seconds = strtol(optarg, &endptr, 0);
                        if ((*endptr != 0) || (seconds <= 0)) {
                                fatal(0, "Invalid --time value.\n");
                        }
                        break;
                case DIRFMT:
                        if (strlen(optarg) > (PATH_MAX - 16)) {
                                fatal(0, "--dirfmt too long\n");
                        }
                        dirfmt = optarg;
                        break;
                case NDIRS:
                        ndirs = strtol(optarg, &endptr, 0);
                        if ((*endptr != 0) || (ndirs <= 0)) {
                                fatal(0, "Invalid --ndirs value.\n");
                        }
                        if ((ndirs > nthreads) &&
                            ((mode == CREATE) || (mode == MKNOD))) {
                                fatal(0, "--ndirs=%d must be less than or "
                                      "equal to the number of threads (%d).\n",
                                      ndirs, nthreads);
                        }
                        break;
                case FILEFMT:
                        if (strlen(optarg) > 4080) {
                                fatal(0, "--filefmt too long\n");
                        }

                        /* Use %%d where you want the file # in the name. */
                        sprintf(filefmt, optarg, myrank);
                        break;
                case NFILES:
                        nfiles = strtol(optarg, &endptr, 0);
                        if ((*endptr != 0) || (nfiles <= 0)) {
                                fatal(0, "Invalid --nfiles value.\n");
                        }
                        break;
                case STRIPES:
                        stripes = strtol(optarg, &endptr, 0);
                        if ((*endptr != 0) || (stripes < 0)) {
                                fatal(0, "Invalid --stripes value.\n");
                        }

                        if (stripes == 0) {
                                openflags |= O_LOV_DELAY_CREATE;
                        } else {
                                fatal(0, "non-zero --stripes value "
                                         "not yet supported.\n");
                        }

                        break;
                case SEED:
                        seed = strtoul(optarg, &endptr, 0);
                        if (*endptr) {
                                fatal(0, "bad --seed option %s\n", optarg);
                        }
                        break;
                case SEEDFILE:
                        seed_file = fopen(optarg, "r");
                        if (!seed_file) {
                              fatal(myrank, "fopen(%s) error: %s\n",
                                      optarg, strerror(errno));
                        }

                        for (i = -1; fgets(tmp, 16, seed_file) != NULL;) {
                                if (++i == myrank)
                                        break;
                        }

                        if (i == myrank) {
                                rc = sscanf(tmp, "%d", &seed);
                                if ((rc != 1) || (seed < 0)) {
                                        fatal(myrank, "Invalid seed value '%s' "
                                              "at line %d in %s.\n",
                                              tmp, i, optarg);
                                }
                        } else {
                                fatal(myrank, "File '%s' too short. Does not "
                                      "contain a seed for thread %d.\n",
                                      optarg, myrank);
                        }

                        fclose(seed_file);
                        break;
                case RANDOM:
                case READDIR:
                        if (mode != LOOKUP && mode != OPEN)  {
                                fatal(0, "--%s can only be specified with "
                                         "--lookup, or --open.\n",
                                      (char *)longOpts[index].name);
                        }
                        order = rc;
                        break;
                case IGNORE:
                        ++ignore;
                        break;
                case DEBUG:
                        ++debug;
                case VERBOSE:
                        ++verbose;
                        break;
                case HELP:
                        usage(stdout, NULL);
			break;
		case MNT:
			if (strlen(optarg) > (PATH_MAX - 16))
				fatal(0, "--mnt too long\n");
			mntfmt = optarg;
			break;
		case MNTCOUNT:
			mnt_count = strtol(optarg, &endptr, 0);
			if ((*endptr != 0) || (mnt_count <= 0)) {
				fatal(0, "Invalid --mnt_count value %s.\n",
				      optarg);
			}
			break;
		case MDTCOUNT:
			mdt_count = strtol(optarg, &endptr, 0);
			if ((*endptr != 0) || (mdt_count <= 0)) {
				fatal(0, "Invalid --mdt_count value %s.\n",
				      optarg);
			}
			break;
                default:
                        usage(stderr, "unrecognized option: '%c'.\n", optopt);
                }
        }

        if (optind < argc) {
                usage(stderr, "too many arguments %d >= %d.\n", optind, argc);
        }

	if ((mnt_count != -1 && mntfmt == NULL) ||
	    (mnt_count == -1 && mntfmt != NULL)) {
		usage(stderr, "mnt_count and mntfmt must be specified at the "
			     "same time\n");
	}

	if (mode == CREATE || mode == MKNOD || mode == UNLINK ||
	    mode == STAT || mode == SETXATTR) {
		if (seconds != 0) {
			if (nfiles == 0)
				nfiles = INT_MAX;
		} else if (nfiles == 0) {
			usage(stderr, "--nfiles or --time must be specified "
				      "with %s.\n", cmd);
		}
        } else if (mode == LOOKUP || mode == OPEN) {
                if (seconds != 0) {
                        if (iters == 0)
                                iters = INT_MAX;
                } else if (iters == 0) {
                        usage(stderr, "--iters or --time must be specifed "
                                      "with %s.\n", cmd);
                }

                if (nfiles == 0) {
                        usage(stderr, "--nfiles must be specifed with --%s.\n",
                              cmd);
                }

                if (seed == 0) {
                        int fd = open("/dev/urandom", O_RDONLY);

                        if (fd >= 0) {
                                if (read(fd, &seed, sizeof(seed)) <
                                    sizeof(seed))
                                        seed = time(0);
                                close(fd);
                        } else {
                                seed = time(0);
                        }
                }

                srand(seed);

                dmesg("%s: rank %d seed %d (%s).\n", prog, myrank, seed,
                      (order == RANDOM) ? "random_order" : "readdir_order");
        } else {
		usage(stderr, "one --create, --mknod, --open, --stat,"
#ifdef HAVE_MDC_LOOKUP
		      " --lookup,"
#endif
		      " --unlink or --setxattr must be specifed.");
        }

        /* support for multiple threads in a dir, set begin/end appropriately.*/
        dirnum = myrank % ndirs;
        dirthreads = nthreads / ndirs;
        if (nthreads > (ndirs * dirthreads + dirnum))
                ++dirthreads;

        offset = myrank / ndirs;

        tmpend = begin + nfiles - 1;
        if (tmpend <= 0)
                tmpend = INT_MAX;

        end = begin + (nfiles / dirthreads) * dirthreads + offset;
        if ((end > tmpend) || (end <= 0))
                end -= dirthreads;

	/* make sure mnt_count <= nthreads, otherwise it might div 0 in
	 * the following test */
	if (mnt_count > nthreads)
		mnt_count = nthreads;

        begin += offset;
        if (begin < 0)
                begin = INT_MAX;

	beginsave = begin;

        dmesg("%d: iters %d nfiles %d time %d begin %d end %d dirthreads %d."
              "\n", myrank, iters, nfiles, seconds, begin, end, dirthreads);

        if (dirfmt == NULL) {
                strcpy(dir, ".");
        } else {
		int dir_len = 0;

		if (mntfmt != NULL) {
			sprintf(dir, mntfmt, (myrank / (nthreads/mnt_count)));
			strcat(dir, "/");
			dir_len = strlen(dir);
		}
		sprintf(dir + dir_len, dirfmt, dirnum);

		if (mdt_count > 1) {
			struct stat sb;
			if (stat(dir, &sb) == 0) {
				if (!S_ISDIR(sb.st_mode))
					fatal(myrank, "'%s' is not dir\n", dir);
			} else if (errno == ENOENT) {
				sprintf(mkdir_cmd, "lfs mkdir -i %d %s",
					myrank % mdt_count, dir);
			} else {
				fatal(myrank, "'%s' stat failed\n", dir);
			}
		} else {
			sprintf(mkdir_cmd, "mkdir -p %s", dir);
		}

		dmesg("%d: %s\n", myrank, mkdir_cmd);
#ifdef _LIGHTWEIGHT_KERNEL
		printf("NOTICE: not running system(%s)\n", mkdir_cmd);
#else
		rc = system(mkdir_cmd);
		if (rc)
			fatal(myrank, "'%s' failed.\n", mkdir_cmd);
#endif

                rc = chdir(dir);
                if (rc) {
                        fatal(myrank, "unable to chdir to '%s'.\n", dir);
                }
        }
}
Example #21
0
int fire_worker_start(int queue_id)
{
	int ret, i, j, k, prot, send_ret;

	fire_worker_t *cc = &(workers[queue_id]); 
	assert(ps_init_handle(&(cc->server_handle)) == 0);
	assert(ps_init_handle(&(cc->client_handle)) == 0);

	struct ps_queue server_queue, client_queue;
	server_queue.ifindex = config->server_ifindex;
	server_queue.qidx = queue_id;
	client_queue.ifindex = config->client_ifindex;
	client_queue.qidx = queue_id;

	assert(ps_attach_rx_device(&(cc->server_handle), &server_queue) == 0);
	assert(ps_attach_rx_device(&(cc->client_handle), &client_queue) == 0);

	struct ps_chunk client_chunk, send_client_chunk, server_chunk, send_server_chunk;
	assert(ps_alloc_chunk(&(cc->client_handle), &client_chunk) == 0);
	assert(ps_alloc_chunk(&(cc->client_handle), &send_client_chunk) == 0);
	assert(ps_alloc_chunk(&(cc->server_handle), &server_chunk) == 0);
	assert(ps_alloc_chunk(&(cc->server_handle), &send_server_chunk) == 0);

	client_chunk.queue.ifindex = config->client_ifindex;
	client_chunk.queue.qidx = queue_id;
	send_client_chunk.queue.ifindex = config->client_ifindex;
	send_client_chunk.queue.qidx = queue_id;
	server_chunk.queue.ifindex = config->server_ifindex;
	server_chunk.queue.qidx = queue_id;
	send_server_chunk.queue.ifindex = config->server_ifindex;
	send_server_chunk.queue.qidx = queue_id;

	int num_pkt_to_client = 0, num_pkt_to_server = 0;
	int pret;

	gettimeofday(&(cc->startime), NULL);

#if defined(HIPAC_TCB)
	int hipac_cnt = 0;
#endif

	for (;;) {
		num_pkt_to_client = 0;
		num_pkt_to_server = 0;
		j = 0;
		k = 0;

		client_chunk.cnt = config->io_batch_num;
		client_chunk.recv_blocking = 0;

		ret = ps_recv_chunk(&(cc->client_handle), &client_chunk);
		if (ret <= 0) {
			/* Receive nothing from server, go to the start of the loop to process client again */
			goto process_server;
		}
		cc->total_packets += ret;

		int action;

		for (i = 0; i < ret; i ++) {
			prot = process_packet(client_chunk.buf + client_chunk.info[i].offset, client_chunk.info[i].len);
			switch (prot) {
				case TCP_SYN_SENT:
					action = HiPAC(client_chunk.buf + client_chunk.info[i].offset, client_chunk.info[i].len, l);
					if(action == FORWARD) {
						// first handshake packet
						// construct the response, and send back to client
						//fprint(INFO, "1) TCP_SYN_SENT\n");
						send_client_chunk.info[j].len = client_chunk.info[i].len;
						send_client_chunk.info[j].offset = j * PS_MAX_PACKET_SIZE;
						memcpy(send_client_chunk.buf + send_client_chunk.info[j].offset,
								client_chunk.buf + client_chunk.info[i].offset, client_chunk.info[i].len);
						form_syn_response(send_client_chunk.buf + send_client_chunk.info[j].offset,
								send_client_chunk.info[j].len);
						pret = process_packet(send_client_chunk.buf 
								+ send_client_chunk.info[j].offset, send_client_chunk.info[j].len);
#if 0
						if(pret != TCP_SYN_RECV){
							printf("pret is %d\n", pret);
							printf("client:\n");
							dmesg(client_chunk.buf + client_chunk.info[i].offset);
							printf("server:\n");
							dmesg(send_client_chunk.buf + send_client_chunk.info[j].offset);
							exit(0);
						}
#endif
						assert(pret == TCP_SYN_RECV);
						//fprint(INFO, "2) TCP_SYN_RECV\n");
						j ++;
					}
					else{ 
					//	hipac_cnt ++;
					//	if(hipac_cnt > 0) printf("hipac filter : %d\n", hipac_cnt);
						delete_tcp(client_chunk.buf + client_chunk.info[i].offset);
					}			
					break;

				case TCP_ESTABLISHED:
					// the 3rd handshake packet
					// do nothing and wait for client's real request
					//fprint(INFO, "3) TCP_ESTABLISHED\n");
					break;

				case -2:
					//fprint(INFO, "two buckets full\n");
					break;

				case -1:
					//fprint(INFO, "Error pkt, don't forward to server.\n");
					break;

				default:
					// normal packet, send to server
					//fprint(INFO, "4) Normal packet, send to server\n");
					send_server_chunk.info[k].len = client_chunk.info[i].len;
					send_server_chunk.info[k].offset = k * PS_MAX_PACKET_SIZE;
					memcpy(send_server_chunk.buf + send_server_chunk.info[k].offset,
							client_chunk.buf + client_chunk.info[i].offset, client_chunk.info[i].len);
					k ++;
					break;
			}

			cc->total_bytes += client_chunk.info[i].len; 

		}
	
		if (j > 0) {
			//fprint(INFO, "sending %d SYN/ACK packet to client, queue_id %d, ifindex %d\n", j, queue_id, config->client_ifindex);
			send_client_chunk.cnt = j;
			send_ret = ps_send_chunk(&(cc->client_handle), &send_client_chunk);
			if (send_ret < 0)
				fprint(ERROR, "send packet fail, ret = %d\n", send_ret);
		}

		if (k > 0) {
			//fprint(INFO, "sending %d packets of established connection to server, queue_id %d, ifindex %d\n", k, queue_id, config->server_ifindex);
			send_server_chunk.cnt = k;
			send_ret = ps_send_chunk(&(cc->server_handle), &send_server_chunk);
			if (send_ret < 0)
				fprint(ERROR, "send packet fail, ret = %d\n", send_ret);
		}
#if 0
		/* FIXME: cannot send all packets
		while (ret > 0) {
			chunk.cnt = ret;
			send_ret = ps_send_chunk(&(cc->handle), &send_chunk);
			if (send_ret < 0)
				fprint(ERROR, "send packet fail, ret = %d\n", send_ret);
			ret -= send_ret;
			//assert(ret >= 0);
		}*/
#endif

process_server:
		/*----------------------------------------------------------------------------------*/
		/* Now process server side packet*/
		server_chunk.cnt = config->io_batch_num;
		//server_chunk.recv_blocking = 0;	//modify at the frist time

		server_chunk.recv_blocking = 0;
		j = 0;

		ret = ps_recv_chunk(&(cc->server_handle), &server_chunk);
		if (ret <= 0) {
			if (errno == EINTR)
				continue;
			/* Receive nothing from server, go to the start of the loop to process client again */
			continue;
		}
		for (i = 0; i < ret; i ++) {
			prot = process_packet(server_chunk.buf + server_chunk.info[i].offset, server_chunk.info[i].len);
			if (prot == 0) {
				send_client_chunk.info[j].len = server_chunk.info[i].len;
				send_client_chunk.info[j].offset = j * PS_MAX_PACKET_SIZE;
				memcpy(send_client_chunk.buf + send_client_chunk.info[j].offset,
					server_chunk.buf + server_chunk.info[i].offset, server_chunk.info[i].len);
				j ++;
			} else {
				fprint(ERROR, "wrong packet from server\n");
			}
		}

		if (j > 0) {
			fprint(DEBUG, "sending packet, queue_id %d, num %d, index %d\n", queue_id, ret, config->client_ifindex);
			send_client_chunk.cnt = j;
			send_ret = ps_send_chunk(&(cc->client_handle), &send_client_chunk);
			if (send_ret < 0)
				fprint(ERROR, "send packet fail, ret = %d\n", send_ret);
		}
	}
	return 0;
}
Example #22
0
// main
int CSysInfoWidget::exec(CMenuTarget *parent, const std::string &/*actionKey*/)
{
	int res = menu_return::RETURN_REPAINT;

	if(mode == SYSINFO)
	{
		sysinfo();
	}
	else if(mode == DMESGINFO)
	{
		dmesg();
	}
	else if(mode == CPUINFO)
	{
		cpuinfo();
	}
	else if(mode == PSINFO)
	{
		ps();
	}

	if (parent)
		parent->hide();

	paintHead();
	paint();
	paintFoot();
	
	frameBuffer->blit();

	neutrino_msg_t msg; 
	neutrino_msg_data_t data;
	int timercount = 0;
	unsigned long long timeoutEnd = g_RCInput->calcTimeoutEnd(5);

	while (msg != (neutrino_msg_t) g_settings.key_channelList_cancel)
	{
		g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd );

		if (msg <= CRCInput::RC_MaxRC  ) 
			timeoutEnd = g_RCInput->calcTimeoutEnd(5);
		
		if (msg == CRCInput::RC_timeout)
		{
			if (mode == SYSINFO)
			{
				timercount = 0;
				sysinfo();
				selected = 0;
				paintHead();
				paint();
				paintFoot();
			}
			
			if ((mode == DMESGINFO) && (++timercount>11))
			{
				timercount = 0;
				dmesg();
				paintHead();
				paint();
				paintFoot();
			}
			
			if ((mode == PSINFO)&&(refreshIt == true))
			{
				timercount = 0;
				ps();
				paintHead();
				paint();
				paintFoot();
			}

			timeoutEnd = g_RCInput->calcTimeoutEnd(5);
			g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd );
		}
		
		if ( ((int) msg == g_settings.key_channelList_pageup) && (mode != SYSINFO))
		{
			int step = 0;
			int prev_selected = selected;

			step =  ((int) msg == g_settings.key_channelList_pageup) ? listmaxshow : 1;  // browse or step 1
			selected -= step;
			if((prev_selected - step) < 0) 
				selected = syscount - 1;
			
			if(state == beDefault)
			{
				paintItem(prev_selected - liststart);
				unsigned int oldliststart = liststart;
				liststart = (selected/listmaxshow)*listmaxshow;
				if(oldliststart!=liststart) 
					paint();
				else 
					paintItem(selected - liststart);
			}
		}
		else if (((int) msg == g_settings.key_channelList_pagedown) && (mode != SYSINFO))
		{
			int step = 0;
			int prev_selected = selected;

			step =  ((int) msg == g_settings.key_channelList_pagedown) ? listmaxshow : 1;  // browse or step 1
			selected += step;
			if((int)selected >= syscount) 
				selected = 0;
			
			if(state == beDefault)
			{
				paintItem(prev_selected - liststart);
				unsigned int oldliststart = liststart;
				liststart = (selected/listmaxshow)*listmaxshow;
				if(oldliststart != liststart) 
					paint();
				else 
					paintItem(selected - liststart);
			}
		}
		else if ((msg == CRCInput::RC_red) && (mode != SYSINFO))
		{
			mode = SYSINFO;
			sysinfo();
			selected = 0;
			paintHead();
			paint();
			paintFoot();

		}
		else if ((msg == CRCInput::RC_green) && (mode != DMESGINFO))
		{
			mode = DMESGINFO;
			timercount = 0;
			dmesg();
			selected = 0;
			paintHead();
			paint();
			paintFoot();
		}
		else if ((msg == CRCInput::RC_yellow) && (mode != CPUINFO))
		{
			mode = CPUINFO;
			cpuinfo();
			selected = 0;
			paintHead();
			paint();
			paintFoot();
		}
		else if (msg == CRCInput::RC_blue)
		{
			mode = PSINFO;
			ps();
			selected = 0;
			paintHead();
			paint();
			paintFoot();
		}
		else
		{
			CNeutrinoApp::getInstance()->handleMsg( msg, data );
			// kein canceling...
		}

		frameBuffer->blit();	
	}
	
	hide();
	
	return res;
}
Example #23
0
int liballoc_abort(int code)
{
	dmesg("%!liballoc_abort!");
	return 0;
}