Esempio n. 1
0
File: offload.c Progetto: krzk/linux
static struct ns_common *bpf_prog_offload_info_fill_ns(void *private_data)
{
	struct ns_get_path_bpf_prog_args *args = private_data;
	struct bpf_prog_aux *aux = args->prog->aux;
	struct ns_common *ns;
	struct net *net;

	rtnl_lock();
	down_read(&bpf_devs_lock);

	if (aux->offload) {
		args->info->ifindex = aux->offload->netdev->ifindex;
		net = dev_net(aux->offload->netdev);
		get_net(net);
		ns = &net->ns;
	} else {
		args->info->ifindex = 0;
		ns = NULL;
	}

	up_read(&bpf_devs_lock);
	rtnl_unlock();

	return ns;
}
/* Updates the load graph when the timeout expires */
static gboolean
load_graph_update (gpointer user_data)
{
	LoadGraph * const g = static_cast<LoadGraph*>(user_data);

	if (g->render_counter == g->frames_per_unit - 1) {
		std::rotate(&g->data[0], &g->data[LoadGraph::NUM_POINTS - 1], &g->data[LoadGraph::NUM_POINTS]);

		switch (g->type) {
		case LOAD_GRAPH_CPU:
			get_load(g);
			break;
		case LOAD_GRAPH_MEM:
			get_memory(g);
			break;
		case LOAD_GRAPH_NET:
			get_net(g);
			break;
		default:
			g_assert_not_reached();
		}
	}

	if (g->draw)
		load_graph_draw (g);

	g->render_counter++;

	if (g->render_counter >= g->frames_per_unit)
		g->render_counter = 0;

	return TRUE;
}
Esempio n. 3
0
static struct nfulnl_instance *
instance_create(struct net *net, u_int16_t group_num,
		u32 portid, struct user_namespace *user_ns)
{
	struct nfulnl_instance *inst;
	struct nfnl_log_net *log = nfnl_log_pernet(net);
	int err;

	spin_lock_bh(&log->instances_lock);
	if (__instance_lookup(log, group_num)) {
		err = -EEXIST;
		goto out_unlock;
	}

	inst = kzalloc(sizeof(*inst), GFP_ATOMIC);
	if (!inst) {
		err = -ENOMEM;
		goto out_unlock;
	}

	if (!try_module_get(THIS_MODULE)) {
		kfree(inst);
		err = -EAGAIN;
		goto out_unlock;
	}

	INIT_HLIST_NODE(&inst->hlist);
	spin_lock_init(&inst->lock);
	/* needs to be two, since we _put() after creation */
	refcount_set(&inst->use, 2);

	timer_setup(&inst->timer, nfulnl_timer, 0);

	inst->net = get_net(net);
	inst->peer_user_ns = user_ns;
	inst->peer_portid = portid;
	inst->group_num = group_num;

	inst->qthreshold 	= NFULNL_QTHRESH_DEFAULT;
	inst->flushtimeout 	= NFULNL_TIMEOUT_DEFAULT;
	inst->nlbufsiz 		= NFULNL_NLBUFSIZ_DEFAULT;
	inst->copy_mode 	= NFULNL_COPY_PACKET;
	inst->copy_range 	= NFULNL_COPY_RANGE_MAX;

	hlist_add_head_rcu(&inst->hlist,
		       &log->instance_table[instance_hashfn(group_num)]);


	spin_unlock_bh(&log->instances_lock);

	return inst;

out_unlock:
	spin_unlock_bh(&log->instances_lock);
	return ERR_PTR(err);
}
Esempio n. 4
0
int
main(void) {
	Display *dpy;
	struct iwreq wreq;
	snd_mixer_t *handle;
	snd_mixer_elem_t *elem;
	snd_mixer_selem_id_t *vol_info;
	int sockfd, loops = 60;
	char *status, *mpd, *net, *vol, *bat, *clk;

	if(!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmst: cannot open display.\n");
		exit(EXIT_FAILURE);
	}

	memset(&wreq, 0, sizeof(struct iwreq));
	snprintf(wreq.ifr_name, sizeof(WIRELESS_DEVICE), WIRELESS_DEVICE);
	sockfd = socket(AF_INET, SOCK_DGRAM, 0);

	snd_mixer_open(&handle, 0);
	snd_mixer_attach(handle, "default");
	snd_mixer_selem_register(handle, NULL, NULL);
	snd_mixer_load(handle);
	snd_mixer_selem_id_malloc(&vol_info);
	snd_mixer_selem_id_set_name(vol_info, VOL_CH);
	elem = snd_mixer_find_selem(handle, vol_info);
	if(elem == NULL) {
		fprintf(stderr, "dwmst: can not open device.\n");
		cleanup(dpy, sockfd, handle, vol_info);
		exit(EXIT_FAILURE);
	}

	for(;;sleep(INTERVAL)) {
		if(++loops > 60) {
			loops = 0;
			mpd = get_mpd();
			net = get_net(wreq, sockfd);
			bat = get_bat();
			clk = get_time();
		}
		vol = get_vol(handle, elem);
		status = smprintf("%s  %s  %s  %s  %s", mpd, net, vol, bat, clk);
		setstatus(dpy, status);
		free(vol);
		free(status);
	}

	free(mpd);
	free(net);
	free(bat);
	free(clk);
	cleanup(dpy, sockfd, handle, vol_info);
	exit(EXIT_SUCCESS);
}
Esempio n. 5
0
/**
 * alloc_fs_context - Create a filesystem context.
 * @fs_type: The filesystem type.
 * @reference: The dentry from which this one derives (or NULL)
 * @sb_flags: Filesystem/superblock flags (SB_*)
 * @sb_flags_mask: Applicable members of @sb_flags
 * @purpose: The purpose that this configuration shall be used for.
 *
 * Open a filesystem and create a mount context.  The mount context is
 * initialised with the supplied flags and, if a submount/automount from
 * another superblock (referred to by @reference) is supplied, may have
 * parameters such as namespaces copied across from that superblock.
 */
static struct fs_context *alloc_fs_context(struct file_system_type *fs_type,
				      struct dentry *reference,
				      unsigned int sb_flags,
				      unsigned int sb_flags_mask,
				      enum fs_context_purpose purpose)
{
	int (*init_fs_context)(struct fs_context *);
	struct fs_context *fc;
	int ret = -ENOMEM;

	fc = kzalloc(sizeof(struct fs_context), GFP_KERNEL);
	if (!fc)
		return ERR_PTR(-ENOMEM);

	fc->purpose	= purpose;
	fc->sb_flags	= sb_flags;
	fc->sb_flags_mask = sb_flags_mask;
	fc->fs_type	= get_filesystem(fs_type);
	fc->cred	= get_current_cred();
	fc->net_ns	= get_net(current->nsproxy->net_ns);

	mutex_init(&fc->uapi_mutex);

	switch (purpose) {
	case FS_CONTEXT_FOR_MOUNT:
		fc->user_ns = get_user_ns(fc->cred->user_ns);
		break;
	case FS_CONTEXT_FOR_SUBMOUNT:
		fc->user_ns = get_user_ns(reference->d_sb->s_user_ns);
		break;
	case FS_CONTEXT_FOR_RECONFIGURE:
		/* We don't pin any namespaces as the superblock's
		 * subscriptions cannot be changed at this point.
		 */
		atomic_inc(&reference->d_sb->s_active);
		fc->root = dget(reference);
		break;
	}

	/* TODO: Make all filesystems support this unconditionally */
	init_fs_context = fc->fs_type->init_fs_context;
	if (!init_fs_context)
		init_fs_context = legacy_init_fs_context;

	ret = init_fs_context(fc);
	if (ret < 0)
		goto err_fc;
	fc->need_free = true;
	return fc;

err_fc:
	put_fs_context(fc);
	return ERR_PTR(ret);
}
Esempio n. 6
0
//{{{ int main(int argc,char** argv)
int main(int argc,char** argv)
{
	//get_config();
	format_msg(0);//初次运行时获取天气
	get_batt();// 初次运行时获取电量
	get_cpu();//cpu
	get_mem();//mem
	get_net();//net
	get_temp();//temperature
	get_mailchk();//2014-4-2添加,邮件检查的显示。
	disp_msg();
	exit(0);
}//}}}
Esempio n. 7
0
static struct afs_super_info *afs_alloc_sbi(struct fs_context *fc)
{
	struct afs_fs_context *ctx = fc->fs_private;
	struct afs_super_info *as;

	as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL);
	if (as) {
		as->net_ns = get_net(fc->net_ns);
		if (ctx->dyn_root) {
			as->dyn_root = true;
		} else {
			as->cell = afs_get_cell(ctx->cell);
			as->volume = __afs_get_volume(ctx->volume);
		}
	}
	return as;
}
Esempio n. 8
0
static struct net *get_proc_task_net(struct inode *dir)
{
	struct task_struct *task;
	struct nsproxy *ns;
	struct net *net = NULL;

	rcu_read_lock();
	task = pid_task(proc_pid(dir), PIDTYPE_PID);
	if (task != NULL) {
		ns = task_nsproxy(task);
		if (ns != NULL)
			net = get_net(ns->net_ns);
	}
	rcu_read_unlock();

	return net;
}
Esempio n. 9
0
struct replay_interface* find_interface(uint32_t net_addr, uint32_t mask_addr) {

	struct replay_interface *search_if, *found;
	struct replay_list *search_item;
	uint32_t if_net;

	search_item = replay0->iflist;
	found = NULL;

	while(search_item) {
		if(search_item->object) {
			search_if = (struct replay_interface *)search_item->object;
			if_net = get_net(search_if->ip.s_addr,search_if->mask.s_addr);
			if (if_net == net_addr && mask_addr == search_if->mask.s_addr) {
				found = search_if;
			}
		}
		search_item = search_item->next;
	}
	return found;
}
Esempio n. 10
0
/**
 * vfs_dup_fc_config: Duplicate a filesystem context.
 * @src_fc: The context to copy.
 */
struct fs_context *vfs_dup_fs_context(struct fs_context *src_fc)
{
	struct fs_context *fc;
	int ret;

	if (!src_fc->ops->dup)
		return ERR_PTR(-EOPNOTSUPP);

	fc = kmemdup(src_fc, sizeof(struct fs_context), GFP_KERNEL);
	if (!fc)
		return ERR_PTR(-ENOMEM);

	mutex_init(&fc->uapi_mutex);

	fc->fs_private	= NULL;
	fc->s_fs_info	= NULL;
	fc->source	= NULL;
	fc->security	= NULL;
	get_filesystem(fc->fs_type);
	get_net(fc->net_ns);
	get_user_ns(fc->user_ns);
	get_cred(fc->cred);
	if (fc->log)
		refcount_inc(&fc->log->usage);

	/* Can't call put until we've called ->dup */
	ret = fc->ops->dup(fc, src_fc);
	if (ret < 0)
		goto err_fc;

	ret = security_fs_context_dup(fc, src_fc);
	if (ret < 0)
		goto err_fc;
	return fc;

err_fc:
	put_fs_context(fc);
	return ERR_PTR(ret);
}
Esempio n. 11
0
int main(int argc, char** argv)
{
    srand(time(NULL));
    int numtasks, worldrank, rank, i, tag=1;
    int coords[2];
    int dims[2], periods[2]={0, 0}, reorder=0;

    int cart_coords[2];
    int target_rank;

    dims[0] = X;
    dims[1] = Y;

    // Two arrays of fish, one for the whole (only used in initialization
    // and the other to hold each process's groups)
    fish_group my_groups[POPULATION];
    int num_fish_in_cell = 0;

    net nets[NETS];

    MPI_Comm cartcomm;

    // createDimensions(dims, SIZE);

    MPI_Init(&argc, &argv);

    create_mpi_datatypes();

    // Get rank and size of the world
    MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
    MPI_Comm_rank(MPI_COMM_WORLD, &worldrank);

    MPI_Cart_create(MPI_COMM_WORLD, 2, dims, periods, reorder, &cartcomm);
    MPI_Comm_rank(cartcomm, &rank);

    MPI_Cart_coords(cartcomm, rank, 2, coords);

    if(rank == 0){
        // Populate the world
        printf("World: %dx%d (size:%dx%d)\n", dims[0], dims[1], WORLD_HEIGHT, WORLD_WIDTH);
        populate(my_groups, POPULATION, WORLD_WIDTH, WORLD_HEIGHT);
        num_fish_in_cell = POPULATION;
        for(i = 0; i < POPULATION; i++){
            printf("fish: %d, x=%d, y=%d\n", my_groups[i].num, my_groups[i].x, my_groups[i].y);
        }
        for(i = 0; i < NETS; i++){
            nets[i] = get_net(WORLD_WIDTH, WORLD_HEIGHT);
            printf("net: %d, x=%d, y=%d\n", i, nets[i].x, nets[i].y);
        }
    }

    MPI_Bcast(nets, NETS, mpi_net, 0, cartcomm);

    int j = 0;

    fish_group received[POPULATION];
    MPI_Request recv_request;

    MPI_Irecv(received, POPULATION, mpi_fish_group,
        MPI_ANY_SOURCE, tag, cartcomm, &recv_request);
    while(j++ < ITERATIONS){
        int sends = 0;
        int testdone, probedone;

        MPI_Request requests[numtasks];
        // MPI_Status status[numtasks];

        MPI_Status recv_status, probe_status;


        int send_counts[numtasks];
        for(i = 0; i < numtasks; i++){
            send_counts[i] = 0;
        }

        fish_group send_objects[numtasks][num_fish_in_cell];

        for(i = 0; i < num_fish_in_cell; i++){
            if(my_groups[i].num == 0){
                remove_element(my_groups, i, num_fish_in_cell--);
                i--;
                continue;
            }
            get_cart_coords(cart_coords, &my_groups[i], WORLD_WIDTH, WORLD_HEIGHT, dims[0], dims[1]);
            MPI_Cart_rank(cartcomm, cart_coords, &target_rank);
            if(rank != target_rank){
                int sc = send_counts[target_rank];
                send_counts[target_rank] += 1;
                send_objects[target_rank][sc] = my_groups[i];
                remove_element(my_groups, i, num_fish_in_cell--);
                i--;
            }
        }

        for(i = 0; i < numtasks; i++){
            if(send_counts[i] > 0){
                // printf("Rank %d: Sending %d groups to %d in loop %d\n", rank, send_counts[i], i, j);
                MPI_Isend(send_objects[i], send_counts[i], mpi_fish_group,
                    i, tag, cartcomm, &requests[sends++]);
                // MPI_Send(send_objects[i], send_counts[i], mpi_fish_group,
                //     i, tag, cartcomm);
            }
        }
        MPI_Barrier(cartcomm);
        struct timespec tim;
        tim.tv_sec  = 0;
        // tim.tv_nsec = 500000000L;
        tim.tv_nsec = 50000000L;
        nanosleep(&tim, NULL);

        MPI_Iprobe(MPI_ANY_SOURCE, tag, cartcomm, &probedone, &probe_status);

        MPI_Test(&recv_request, &testdone, &recv_status);

        int count = 0;
        while(testdone){
            MPI_Get_count(&recv_status, mpi_fish_group, &count);
            for(i = 0; i < count; i++){
                my_groups[num_fish_in_cell++] =received[i];
            }
            MPI_Irecv(received, POPULATION, mpi_fish_group,
                MPI_ANY_SOURCE, tag, cartcomm, &recv_request);

            MPI_Iprobe(MPI_ANY_SOURCE, tag, cartcomm, &probedone, &probe_status);

            MPI_Test(&recv_request, &testdone, &recv_status);
        }

        if(OUTPUT){
            for(i=0; i < num_fish_in_cell; i++){
                printf("--fish-%d-%d-%d-%d-%d\n", j, my_groups[i].num, my_groups[i].x, my_groups[i].y, rank);
            }
            for(i=0; i < NETS; i++){
                printf("--net-%d-%d-%d-%d-%d-%d\n", j, i, nets[i].fish, NET_SIZE, nets[i].x, nets[i].y);
            }
        }

        int last_catch[NETS];
        if(rank == 0){
            for(i=0; i < NETS; i++){
                last_catch[i] = nets[i].fish;
            }
        }

        // Update the x,y position of every group according to it's movement speed.
        update(my_groups, num_fish_in_cell, nets, NETS);


        int recvnets = NETS*numtasks;
        net temp_nets[recvnets];

        MPI_Gather(nets, NETS, mpi_net, temp_nets, NETS, mpi_net, 0, cartcomm);

        if(rank == 0){
            int new_catch[NETS];
            for(i=0; i < NETS; i++){
                new_catch[i] = 0;
            }
            for(i=0; i < recvnets; i++){
                int ind = i % NETS;
                int diff = temp_nets[i].fish - last_catch[ind];
                new_catch[ind] += diff;
            }
            for(i=0; i < NETS; i++){
                nets[i].fish += new_catch[i];
            }
        }

        MPI_Bcast(nets, NETS, mpi_net, 0, cartcomm);
    }

    MPI_Finalize();
    return 0;
}
bool module::read_module(string buff, map<string, module*> &map_module, map<string, cell*> &map_cell) {
	try {
		string buff_s = buff;
		string input_line, output_line, wire_line, instance_line;
		std::regex e;
		std::smatch sm;
		std::regex_iterator<std::string::iterator> rit;
		std::regex_iterator<std::string::iterator> rend;

		e = "module ([\\\\\\._a-zA-Z0-9]+)";
		std::regex_search(buff, sm, e);
		sModuleName = sm[1];
		cout << "module_name: " << sModuleName << endl;

		e = "input\\s+([^;]+;)";
		string buff_input = buff;
		while (std::regex_search(buff_input, sm, e)) {
			input_line = sm[1];
			std::regex e_input_line("([\\\\\\w]+)");
			rit = std::regex_iterator<std::string::iterator>(input_line.begin(), input_line.end(), e_input_line);
			while (rit != rend) {
				add_net(rit->str());
				set_input(get_net(rit->str()), true);
				rit++;
			}
			buff_input = sm.suffix().str();
		}

		e = "output\\s+([^;]+;)";
		string buff_output = buff;
		while (std::regex_search(buff_output, sm, e)) {
			output_line = sm[1];
			std::regex e_output_line("([\\\\\\w]+)");
			rit = std::regex_iterator<std::string::iterator>(output_line.begin(), output_line.end(), e_output_line);
			while (rit != rend) {
				add_net(rit->str());
				set_output(get_net(rit->str()), true);
				rit++;
			}
			buff_output = sm.suffix().str();
		}

		e = "wire\\s+([^;]+;)";
		string buff_wire = buff;
		while (std::regex_search(buff_wire, sm, e)) {
			wire_line = sm[1];
			std::regex e_wire_line("([\\\\\\w]+)");
			rit = std::regex_iterator<std::string::iterator>(wire_line.begin(), wire_line.end(), e_wire_line);
			while (rit != rend) {
				add_net(rit->str());
				rit++;
			}
			buff_wire = sm.suffix().str();
		}

		e = "([\\\\\\.\\w]+)\\s+([\\\\\\.\\w]+)\\s*\\((?:.|\\s)*?\\);";
		rit = std::regex_iterator<std::string::iterator>(buff_s.begin(), buff_s.end(), e);
		while (rit != rend) {
			instance_line = rit->str();
			std::regex e_instance_line("([\\\\\\.\\w]+)\\s+([\\\\\\.\\w]+)\\s*\\(((?:.|\\s)*?)\\);");
			if (std::regex_match(instance_line, sm, e_instance_line)) {
				string gate_type = sm[1];
				string instance_name = sm[2];
				string port_info = sm[3];

				if (gate_type != "module") {
					node* new_node = add_node(instance_name, gate_type, map_module, map_cell);

					vector<string> pin_list;
					vector<string> wire_list;
					std::regex e_port_info("\\.([\\\\\\[\\]\\w]+)\\(\\s*([\\\\\\[\\]\\w]+)\\s*\\)");
					std::regex_iterator<std::string::iterator> it_port_info(port_info.begin(), port_info.end(), e_port_info);
					while (it_port_info != rend) {
						string single_port = it_port_info->str();
						smatch sm_single_port;
						if (std::regex_match(single_port, sm_single_port, e_port_info)) {
							connect_wire(get_net(sm_single_port[2]), new_node, sm_single_port[1]);
						}
						it_port_info++;
					}
				}
			}
			rit++;
		}
		commit();
	}
	catch (std::exception &e) {
		cerr << "reading module faild. (read_module)\n";
		cerr << "description: " << e.what();
		destroy();
		return false;
	}
	return true;
}