[SSI] openssi/kernel/cluster/ssi/vproc procfs_subr.c,1.18,1.19
Roger Tsang <[email protected]> Mon, 25 Oct 2010 05:08:58 +0000
| Newsgroups | gmane.linux.cluster.ssic.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/ssic-linux/openssi/kernel/cluster/ssi/vproc
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv3482/cluster/ssi/vproc
Modified Files:
Tag: OPENSSI-FC
procfs_subr.c
Log Message:
Reduce stack usage in ssi_get_tgid_list().
Index: procfs_subr.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/kernel/cluster/ssi/vproc/procfs_subr.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- procfs_subr.c 25 Oct 2010 04:34:58 -0000 1.18
+++ procfs_subr.c 25 Oct 2010 05:08:56 -0000 1.19
@@ -18,11 +18,11 @@
#endif
struct proc_root_readdir_cookie {
+ unsigned int start_index;
unsigned int cur_index;
clusternode_t start_node;
int h_index;
int v_index;
- unsigned int start_index;
unsigned int pid_list[PROC_MAXPIDS];
};
@@ -43,11 +43,11 @@
if (cp == NULL)
return -ENOMEM;
#ifdef PROC_LARGE_MAXPIDS
+ cp->start_index = 0;
cp->cur_index = 0;
cp->start_node = 0;
cp->h_index = 0;
cp->v_index = 0;
- cp->start_index = 0;
#endif
file->private_data = cp;
return 0;
@@ -66,49 +66,48 @@
int
ssi_get_tgid_list(struct file *file, unsigned int index, unsigned int *pids)
{
- int nr_pids = 0;
struct proc_root_readdir_cookie *cp = file->private_data;
- clusternode_t start_node;
- int h_index = 0;
- int v_index = 0;
- int error = 0;
nsc_nodelist_t *nodelist;
nsc_nlcookie_t cookie;
clusternode_t node;
- int pids_size;
- int pids_off;
- unsigned int out_index;
- unsigned int start_index;
u_int *pidsp;
+ int pids_size, nr_pids = 0;
+ unsigned int out_index;
+ int pids_off;
- start_node = 0;
- out_index = 1;
- start_index = index;
- if (cp->start_index != 0 && index >= cp->start_index) {
+ if (cp->start_index && index >= cp->start_index) {
/* Use the saved starting position. */
- start_node = cp->start_node;
- h_index = cp->h_index;
- v_index = cp->v_index;
out_index = cp->cur_index;
- if (index < cp->cur_index) {
+ /* If caller truncated read, fill-in pids from previous read */
+ if (unlikely(index < cp->cur_index)) {
nr_pids = cp->cur_index - index;
+ BUG_ON(nr_pids > PROC_MAXPIDS);
memcpy(pids, cp->pid_list + index - cp->start_index,
nr_pids * sizeof(unsigned int));
index = cp->cur_index;
}
+ BUG_ON(index > cp->cur_index);
+ } else {
+ /* Reset the saved starting position. */
+ cp->start_node = 0;
+ cp->h_index = 0;
+ cp->v_index = 0;
+ out_index = 1;
}
+
/* get node list */
nodelist = clms_get_nsc_nodelist(CLMS_NODE_UP
|CLMS_NODE_HALF_UP
|CLMS_NODE_HALF_DOWN);
-
NSC_NLCOOKIE_INIT(&cookie);
if (NSC_NODELIST_TEST1(nodelist, this_node)) {
node = NSC_NODELIST_GET_NEXT(&cookie,nodelist);
- while ((start_node != 0) && (node != start_node)) {
- node = NSC_NODELIST_GET_NEXT(&cookie,nodelist);
- if (node == CLUSTERNODE_INVAL)
- goto out;
+ if (cp->start_node) {
+ while (node != cp->start_node) {
+ node = NSC_NODELIST_GET_NEXT(&cookie,nodelist);
+ if (node == CLUSTERNODE_INVAL)
+ goto out;
+ }
}
}
else {
@@ -123,10 +122,10 @@
for (;;) {
pids_size = PROC_MAXPIDS - nr_pids;
pidsp = pids + nr_pids;
- error = PVPSOP_GET_TGID_LIST(node, &pidsp,
- &pids_size, &h_index, &v_index);
- if (error)
+ if (PVPSOP_GET_TGID_LIST(node, &pidsp,
+ &pids_size, &cp->h_index, &cp->v_index)) {
pids_size = 0;
+ }
if (out_index != index) {
pids_off = index - out_index;
out_index += pids_size;
@@ -144,23 +143,20 @@
}
}
nr_pids += pids_size;
- if (nr_pids < PROC_MAXPIDS) {
- node = NSC_NODELIST_GET_NEXT(&cookie, nodelist);
- if (node == CLUSTERNODE_INVAL)
- break;
- } else
+ if (nr_pids >= PROC_MAXPIDS)
+ break;
+ node = NSC_NODELIST_GET_NEXT(&cookie, nodelist);
+ if (node == CLUSTERNODE_INVAL)
break;
/* reset index values */
- h_index = 0;
- v_index = 0;
+ cp->h_index = 0;
+ cp->v_index = 0;
}
out:
NSC_NODELIST_FREE(nodelist);
- cp->start_index = start_index;
- cp->cur_index = start_index + nr_pids;
+ cp->start_index = index;
+ cp->cur_index = index + nr_pids;
cp->start_node = node;
- cp->h_index = h_index;
- cp->v_index = v_index;
memcpy(cp->pid_list, pids, nr_pids * sizeof(unsigned int));
return nr_pids;
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev