Exemple #1
0
/** 
	@return -1, no todo information, 0 not started, 1..1000 = 1..100% , 2000 = done */
int done_status (Node *a)
{
	int completion;

	if (prefs.showpercent) {
		completion = node_calc_complete (a);
	} else {
		if (!strcmp(fixnullstring(node_get(a,"type")),"todo")){
			if (node_get(a,"done") && !strcmp(node_get(a,"done"),"yes")) {
				completion = 2000;
			} else {
				completion = 0;
			}
		} else {
			completion = -1;
		}
	}

	/* FIXME this is the wrong location for this code,.. must fixup the drawing code */
	if (!prefs_bullet_empty && completion == -1) {
		char *data = fixnullstring (node_get (a, TEXT));
		int j = 0;

		completion = -2;
		while (data[j]) {
			if (data[j++] != ' ') {
				completion = -1;
				break;
			}
		}
	}
	return completion;
}
Exemple #2
0
int os_uncore_stop(perf_ctl_t *ctl, perf_task_t *task)
{
	task_uncore_t *t = (task_uncore_t *)task;
	node_t *node;
	int i;
	
	if (t->nid >= 0) {
		node = node_get(t->nid);
		if (NODE_VALID(node)) {
			if (node->qpi.qpi_num > 0)
				pf_uncoreqpi_free(node);
			
			if (node->imc.imc_num > 0)
				pf_uncoreimc_free(node);
		}
	} else {
		for (i = 0; i < NNODES_MAX; i++) {
			node = node_get(i);
			if (NODE_VALID(node)) {
				if (node->qpi.qpi_num > 0)
					pf_uncoreqpi_free(node);

				if (node->imc.imc_num > 0)
					pf_uncoreimc_free(node);
			}
		}
	}

	return 0;
}
Exemple #3
0
/*
 * Refresh the information of each node in group. The information
 * includes such as: CPU, physical memory size, free memory size.
 * Get the information from /sys/devices/system/node.
 */
int
node_group_refresh(boolean_t init)
{
	int node_arr[NNODES_MAX];
	int num, i, j, ret = -1;
	node_t *node;

	node_group_lock();
	if (!os_sysfs_node_enum(node_arr, NNODES_MAX, &num)) {
		goto L_EXIT;
	}

	for (i = 0; i < NNODES_MAX; i++) {
		node = node_get(i);
		if (NODE_VALID(node)) {
			if ((j = nid_find(node->nid, node_arr, num)) == -1) {
				node_hotremove(node);
				s_node_group.nnodes--;
			} else {
				node_arr[j] = INVALID_NID;
			}
		}
	}

	for (i = 0; i < NNODES_MAX; i++) {
		node = node_get(i);
		if (!NODE_VALID(node)) {
			if ((j = nid_find(i, node_arr, num)) >= 0) {
				ASSERT(node_arr[j] == i);
				if (init) {
					node_init(node, i, B_FALSE);
				} else {				
					node_init(node, i, B_TRUE);
				}

				s_node_group.nnodes++;
				node_arr[j] = INVALID_NID;
			}
		}
	}

	if (cpu_refresh(init) != 0) {
		goto L_EXIT;
	}

	if (meminfo_refresh() != 0) {
		goto L_EXIT;
	}

	ret = 0;

L_EXIT:
	node_group_unlock();
	return (ret);
}
Exemple #4
0
static inline
avl_tree_node_t *node_get(avl_tree_node_t *n, avl_tree_key_t k) {
    if (!n)
        return n;

    if (k > n->key)
        return node_get(n->right, k);
    if (k < n->key)
        return node_get(n->left, k);

    return n;
}
Exemple #5
0
inline void page_modifySchedule(){
  static int value = 0;
  static schedule s = node_get(node_index);   
  if(pre_page != MODIFY_SCHEDULE) {
    PTLS("Page Modify Schedule");
    lcd.cursor();
    pre_page = MODIFY_SCHEDULE; 
    //Need to reintialize everytime we enter the page but not every refresh
    s = node_get(node_index);
    value = 0;
  }  
  String t = getTimeString(s);
  lcd.print(t);
  lcd.setCursor(0,1);
  lcd.print("Temp: " + (String) s.temperature);
  if (button_input == PLUS_UP || button_input == PLUS_HOLD) {
    if (value == 0) {
      s.day++;
      if (s.day >= 8) s.day = 1;
    } else if (value == 1) {
      s.hour++;
      if (s.hour >= 24) s.hour = 0;
    } else if (value == 2) {
      s.minute++;
      if (s.minute >= 60) s.minute = 0;
    } else if (value == 3) {
      s.temperature++;
      if (s.temperature >= 99) 
        s.temperature = 99;
    }
  } else if (button_input == MINUS_UP || button_input == MINUS_HOLD) {
    if (value == 0) {
      s.day--;
      if (s.day <= 0) s.day = 7;
    } else if (value == 1) {
      s.hour--;
      if (s.hour >= 24) s.hour = 23;
    } else if (value == 2) {
      s.minute--;
      if (s.minute >= 60) s.minute = 59;
    } else if (value == 3) {
      s.temperature--;
      if (s.temperature <= 32 || s.temperature >= 99) 
      s.temperature = 32;
    }
  } else if (button_input == MODE_UP) {
    value += 1;
    value = value % 4;
  } else if (button_input == SET_UP) {
    node_edit(node_index,s);
    switchPage(PICK_SCHEDULE);
  }
}
Exemple #6
0
int
os_uncore_smpl(perf_ctl_t *ctl, perf_task_t *task, int *intval_ms)
{
	task_uncore_t *t = (task_uncore_t *)task;
	node_t *node;
	int ret;

	node = node_get(t->nid);
	if (!NODE_VALID(node))
		return -1;

	ret = pf_uncoreqpi_smpl(node);
	if (ret != 0) {
		disp_profiling_data_fail();
		return ret;
	}

	ret = pf_uncoreimc_smpl(node);
	if (ret == 0)
		disp_profiling_data_ready(*intval_ms);
	else
		disp_profiling_data_fail();

	return (ret);
}
Exemple #7
0
static int uncore_start(perf_ctl_t *ctl, int nid)
{
	node_t *node;
	int ret = -1;
	
	node = node_get(nid);
	if (!NODE_VALID(node))
		return -1;
	
	if (pf_uncoreqpi_setup(node) != 0)
		goto L_EXIT;
	
	if (pf_uncoreimc_setup(node) != 0)
		goto L_EXIT;

	if (pf_uncoreqpi_start(node) != 0)
		goto L_EXIT;
	
	if (pf_uncoreimc_start(node) != 0)
		goto L_EXIT;

	ret = 0;

L_EXIT:
	if (ret < 0) {
		pf_uncoreqpi_free(node);
		pf_uncoreimc_free(node);
	}

	return ret;
}
Exemple #8
0
static int toggle_done_cmd (int argc, char **argv, void *data)
{
	Node *pos = (Node *) data;

	if (strcmp(fixnullstring(node_get(pos,"type")),"todo")) {	/* bail out if not todo info set */
		return (int) pos;
	}

	if (!strcmp(fixnullstring(node_get(pos,"done")),"yes")) {	/* bail out if not todo info set */
		node_set(pos,"done","no");
	} else {
		node_set(pos,"done","yes");
	}

	return (int) pos;
}
Exemple #9
0
/*
 * Get node by CPU id.
 */
node_t *
node_by_cpu(int cpuid)
{
	node_t *node;
	int i, j;

	if (cpuid == INVALID_CPUID) {
		return (NULL);
	}

	for (i = 0; i < NNODES_MAX; i++) {
		node = node_get(i);
		if (!NODE_VALID(node)) {
			continue;
		}

		for (j = 0; j < NCPUS_NODE_MAX; j++) {
			if (cpuid == node->cpus[j].cpuid) {
				return (node);
			}
		}
	}

	return (NULL);
}
Exemple #10
0
bool map_get(Map *map, const void *key, void **value) {
  if (!map->root) {
    return false;
  }

  return node_get(map->root,key, value);
}
Exemple #11
0
static uint64_t
countval_sum(count_value_t *countval_arr, int nid,
	ui_count_id_t ui_count_id)
{
	uint64_t value = 0;
	node_t *node;
	int i, cpuid, num = 0;

	node = node_get(nid);
	if (!NODE_VALID(node)) {
		return (0);
	}

	for (i = 0; i < NCPUS_NODE_MAX; i++) {
		if (num >= node->ncpus) {
			break;
		}

		if ((cpuid = node->cpus[i].cpuid) != INVALID_CPUID) {
			value += ui_perf_count_aggr(ui_count_id,
					countval_arr[cpuid].counts);
			num++;
		}
	}

	return (value);
}
Exemple #12
0
void type(run_params* par) {
	int i;

	if (par->argc < 1) {
		pipe_write_s(par->err, "Too few arguments for 'type'.\n");
		return;
	}

	char* filename = par->args[0];
	node* n = node_get(filename, par->root_node, par->start_node);

	if (n == NULL) {
		pipe_write_s(par->err, "File does not exist.\n");
		return;
	}
	if (n->directory) {
		pipe_write_s(par->err, "File is a directory.\n");
		return;
	}

	if (!node_try_lock(n)) {
		pipe_write_s(par->err, "Can't open the file.\n");
		return;
	}

	for (i = 0; i < n->content_len; i++) {
		pipe_write(par->out, n->content[i]);
	}

	node_unlock(n);
}
Exemple #13
0
int
node_qpi_init(void)
{
	qpi_info_t qpi_tmp[NODE_QPI_MAX];
	int qpi_num, i;
	node_t *node;

	qpi_num = os_sysfs_uncore_qpi_init(qpi_tmp, NODE_QPI_MAX);
	if (qpi_num < 0)
		return -1;

	if (qpi_num == 0) {
		qpi_num = os_sysfs_uncore_upi_init(qpi_tmp, NODE_QPI_MAX);
		if (qpi_num < 0)
			return -1;
	}

	node_group_lock();

	for (i = 0; i < NNODES_MAX; i++) {
		node = node_get(i);
		if (NODE_VALID(node) && (qpi_num > 0)) {
			memcpy(node->qpi.qpi_info, qpi_tmp,
				sizeof(node->qpi.qpi_info));
			node->qpi.qpi_num = qpi_num;
		}
	}

	node_group_unlock();

	debug_print(NULL, 2, "%d QPI/UPI links per node\n", qpi_num);

	return 0;
}
Exemple #14
0
int
node_imc_init(void)
{
	imc_info_t imc_tmp[NODE_IMC_MAX];
	int imc_num, i;
	node_t *node;

	imc_num = os_sysfs_uncore_imc_init(imc_tmp, NODE_IMC_MAX);
	if (imc_num < 0)
		return -1;

	node_group_lock();

	for (i = 0; i < NNODES_MAX; i++) {
		node = node_get(i);
		if (NODE_VALID(node) && (imc_num > 0)) {
			memcpy(node->imc.imc_info, imc_tmp,
				sizeof(node->imc.imc_info));
			node->imc.imc_num = imc_num;
		}
	}

	node_group_unlock();

	debug_print(NULL, 2, "%d memory controllers per node\n", imc_num);

	return 0;
}
Exemple #15
0
static int
cpu_refresh(boolean_t init)
{
	int i, j, num, cpuid_max = -1;
	int cpu_arr[NCPUS_NODE_MAX];
	node_t *node;

	for (i = 0; i < NNODES_MAX; i++) {
		node = node_get(i);
		if (NODE_VALID(node)) {
			if (!os_sysfs_cpu_enum(node->nid, cpu_arr, NCPUS_NODE_MAX, &num)) {
				return (-1);
			}

			if (os_perf_cpuarr_refresh(node->cpus, NCPUS_NODE_MAX, cpu_arr,
				num, init) != 0) {
				return (-1);
			}

			node->ncpus = num;
			j = cpuid_max_get(cpu_arr, num);
			if (cpuid_max < j) {
				cpuid_max = j;
			}
		}
	}

	if (cpuid_max > s_node_group.cpuid_max) {
		s_node_group.cpuid_max = cpuid_max;
	}

	/* Refresh the number of online CPUs */
	g_ncpus = os_sysfs_online_ncpus();
	return (0);
}
Exemple #16
0
static Val_T node_get(Node *h, Key_T key) {
    if (h == NULL) {
        return NULL;
    }
    int i;
    for (i = 0; i != h->num - 1; i++) {
        int cmp = keycmp(key, h->keys[i]);
        if (cmp < 0) {
            return node_get(h->childs[i], key);
        } else if (cmp == 0) {
            return h->vals[i];
        } else {
            continue;
        }
    }
    return node_get(h->childs[i], key);
}
Exemple #17
0
/*
 * Return the memory information for a specified node.
 */
void
node_meminfo(int nid, node_meminfo_t *info)
{
	node_t *node;
	
	if (((node = node_get(nid)) != NULL) &&
		(NODE_VALID(node))) {
		memcpy(info, &node->meminfo, sizeof (node_meminfo_t));	
	}
}
Exemple #18
0
void
node_profiling_clear(void)
{
	node_t *node;
	int i;

	for (i = 0; i < NNODES_MAX; i++) {
		node = node_get(i);
		(void) memset(&node->countval, 0, sizeof (count_value_t));
	}	
}
Exemple #19
0
/*
 * Free the resources of all nodes in group.
 */
static void
node_group_reset(void)
{
	node_t *node;
	int i;

	for (i = 0; i < NNODES_MAX; i++) {
		node = node_get(i);
		node_fini(node);
	}

	s_node_group.nnodes = 0;
}
Exemple #20
0
/* a traversal calculation of completion level
*/
int node_calc_complete (Node *node)
{
	int percent_sum = 0;
	int nodes = 0;

	if (strcmp(fixnullstring(node_get(node,"type")),"todo"))
		return -1;				/* node has no completion status */

	if (node_get(node,"done") && !strcmp(node_get(node,"done"),"yes"))
		return 2000;			/* this node is done */

	if (node_getval (node,"percent_done") != -1)
		return node_getval (node,"percent_done") * 10;

	if (!node_right (node))
		return 0;				/* no undone children,.. completly undone */

	node = node_right (node);

	while (node) {
		switch (node_calc_complete (node)) {
			case -1:
				break;
			case 2000:
				percent_sum += 1000;
				nodes++;
				break;
			default:
				percent_sum += node_calc_complete (node);
				nodes++;
				break;
		}
		node = node_down (node);
	}

	if (nodes)
		return (percent_sum) / (nodes);
	return 0;
}
Exemple #21
0
inline void page_pickSchedule() {
  static byte prev_index = 0;
  if(pre_page != PICK_SCHEDULE) {
    PTLS(" Page Pick Schedule");
    lcd.cursor();
    pre_page = PICK_SCHEDULE; 
    node_index = node_index % (node_size()-1);
    prev_index = node_index + 1;
  }
  
  if (prev_index != node_index) {
    prev_index == node_index;
    schedule s = node_get(node_index);
    String t = getTimeString(s);
    if (mod) lcd.print(F("Mod:"));
    else lcd.print(F("Del: "));
    lcd.print(t);
    lcd.setCursor(0,1);
    lcd.print("Targ Temp: " + (String)s.temperature);
  }
  
  if (button_input == PLUS_UP || button_input == PLUS_HOLD)
  {
    node_index += 1;
    if (node_index >= node_size())
      node_index = 0;
  }
  else if (button_input == MINUS_UP || button_input == MINUS_HOLD)
  {
    node_index -= 1;
    if(node_index < 0) {
      node_index = (node_size()-1);
    }
  }
  else if (button_input == SET_UP)
  {
    if(mod) {
      switchPage(MODIFY_SCHEDULE);
    } else {
      PTLS("Node deleted");
      node_delete(node_index);
      node_index = (node_size()-1);
      prev_index = node_index + 1;
    }
  }
  else if (button_input == MODE_UP)
  {
    switchPage(LIST_MODE);
  }
}
Exemple #22
0
static Oc_bpt_node* node_get_xl(Oc_wu *wu_p, uint64 addr)
{
    Oc_bpt_node *node_p;

    while (1) {
        node_p = node_get(wu_p, addr);
        oc_utl_trk_crt_lock_write(wu_p, &node_p->lock);
        if (node_p->disk_addr != addr) {
            node_release(wu_p, node_p); 
        } else
            break;
    }
    oc_utl_debugassert(addr == node_p->disk_addr);
    
    return node_p;
}
Exemple #23
0
void *cmd_att_get (int argc, char **argv, void *data)
{
	Node *pos = (Node *) data;
	char *cdata;
	
	if(argc!=2){
		cli_outfunf("usage: %s <attribute>",argv[0]);
		return pos;
	}
			
	cdata = node_get (pos, argv[1]);

	if (cdata)
		cli_outfun (cdata);
	return pos;
}
Exemple #24
0
void wc(run_params* par) {
	if (par->argc >= 1) {
		char* filename = par->args[0];
		node* n = node_get(filename, par->root_node, par->start_node);

		if (n == NULL) {
			pipe_write_s(par->err, "File does not exist.\n");
			return;
		}
		if (n->directory) {
			pipe_write_s(par->err, "File is a directory.\n");
			return;
		}

		if (!node_try_lock(n)) {
			pipe_write_s(par->err, "Can't open the file.\n");
			return;
		}

		wc_count(par, n->content, n->name);
		node_unlock(n);

	}
	else {
		int pos, c = -1, buf_size = 300;
		char* buf = (char*)malloc(sizeof(char) * buf_size);

		pos = 0;
		while (true) {
			c = pipe_read(par->in);
			if ((c == -1)) break;
			
			if (pos == buf_size - 1) {
				buf_size *= 2;
				buf = (char*)realloc(buf, sizeof(char*) * buf_size);
			}
			buf[pos] = c;
			pos++;
		}
		buf[pos] = '\0';

		wc_count(par, buf, "");
		free(buf);
		buf = NULL;
	}
}
Exemple #25
0
void rm(run_params* par) {
	if (par->argc < 1) {
		pipe_write_s(par->err, "Too few parameters.\n");
		return;
	}
	char* rm_name = par->args[0];

	node* rm_node = node_get(rm_name, par->root_node, par->start_node);
	if (rm_node == NULL) {
		pipe_write_s(par->err, "File does not exist.\n");
		return;
	}

	int ret = node_delete_recursive(rm_node);
	if (ret != 0) {
		pipe_write_s(par->err, "Error on recursive deleting.\n");
	}
}
Exemple #26
0
static int
meminfo_refresh(void)
{
	int i;
	node_t *node;
	
	for (i = 0; i < NNODES_MAX; i++) {
		node = node_get(i);
		if (NODE_VALID(node)) {
			if (!os_sysfs_meminfo(node->nid, &node->meminfo)) {
				debug_print(NULL, 2, "meminfo_refresh:sysfs_meminfo failed\n");
				return (-1);
			}
		}
	}

	return (0);
}
Exemple #27
0
void *avl_tree_remove_get_data(avl_tree_t *t, avl_tree_key_t k) {
    void *d = NULL;
    bool removed = false;

    assert(t);

#if 0
    n = node_get(t->root, k);
    d = n->data;
#endif

    t->root = node_remove(t->root, k, &removed, &d);

    if (removed)
        --t->count;

    return d;
}
Exemple #28
0
/*
 * Initialization for the node group.
 */
int
node_group_init(void)
{
	int i;
	node_t *node;

	(void) memset(&s_node_group, 0, sizeof (node_group_t));
	if (pthread_mutex_init(&s_node_group.mutex, NULL) != 0) {
		return (-1);
	}

	s_node_group.inited = B_TRUE;
	for (i = 0; i < NNODES_MAX; i++) {
		node = node_get(i);
		node_init(node, INVALID_NID, B_FALSE);
	}

	return (node_group_refresh(B_TRUE));
}
Exemple #29
0
node_t *
node_valid_get(int node_idx)
{
	int i, nvalid = 0;
	node_t *node;

	for (i = 0; i < NNODES_MAX; i++) {
		node = node_get(i);
		if (NODE_VALID(node)) {
			if (node_idx == nvalid) {
				return (node);	
			}
			
			nvalid++;
		}
	}

	return (NULL);
}
Exemple #30
0
/*
 * Walk through the CPUs in a node and call 'func()' for each CPU.
 * The CPU might be INVALID. Note that the function could be only called
 * in perf thread.
 */
int
node_cpu_traverse(pfn_perf_cpu_op_t func, void *arg, boolean_t err_ret,
	pfn_perf_cpu_op_t hotadd_func)
{
	node_t *node;
	perf_cpu_t *cpu;
	int i, j, ret;

	for (i = 0; i < NNODES_MAX; i++) {
		node = node_get(i);
		if (!NODE_VALID(node)) {
			continue;
		}

		for (j = 0; j < NCPUS_NODE_MAX; j++) {
			cpu = &node->cpus[j];
			if (cpu->hotremove) {
				pf_resource_free(cpu);
				cpu->hotremove = B_FALSE;
				cpu->cpuid = INVALID_CPUID;
				continue;
			}

			if ((cpu->hotadd) && (hotadd_func != NULL)) {
				hotadd_func(cpu, arg);
				cpu->hotadd = B_FALSE;
			}

			if ((func != NULL) && (cpu->cpuid != INVALID_CPUID) && (!cpu->hotadd)) {
				if (((ret = func(cpu, arg)) != 0) && (err_ret)) {
					return (ret);					
				} 
			}
		}

		if (node->hotremove) {
			node->nid = INVALID_NID;
			node->hotremove = B_FALSE;
		}
	}

	return (0);
}