[SSI] openssi/procps top.c, 1.1.15.2, 1.1.15.2.2.1 top.h, 1.1.15.2, 1.1.15.2.2.1
Roger Tsang <[email protected]> Sun, 08 Aug 2010 03:41:08 +0000
| Newsgroups | gmane.linux.cluster.ssic.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/ssic-linux/openssi/procps
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv10105
Modified Files:
Tag: OPENSSI-CENTOS
top.c top.h
Log Message:
OpenSSI changes for procps-3.2.3-8.17.el4_8.2
Index: top.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/procps/Attic/top.c,v
retrieving revision 1.1.15.2
retrieving revision 1.1.15.2.2.1
diff -u -d -r1.1.15.2 -r1.1.15.2.2.1
--- top.c 8 Aug 2010 03:33:58 -0000 1.1.15.2
+++ top.c 8 Aug 2010 03:41:06 -0000 1.1.15.2.2.1
@@ -42,6 +42,7 @@
#include <time.h>
#include <unistd.h>
#include <values.h>
+#include <linux/cluster.h> /* OpenSSI */
#include "proc/devname.h"
#include "proc/wchan.h"
@@ -92,6 +93,8 @@
static char Msg_delayed [SMLBUFSIZ];
static int Msg_awaiting = 0;
+static int localview = 0; /* OpenSSI: flag to indicate if top is running in localview mode */
+
/* 1 = use /proc/#/status, 0 = use /proc/#/statm */
static int use_status_vmsize = 0;
@@ -202,6 +205,7 @@
SCB_NUMx(P_NCE, nice)
SCB_NUMx(P_CPN, processor)
SCB_NUM1(P_CPU, pcpu)
+SCB_NUM1(P_NOD, enode)
// also serves P_TM2 !
static int sort_P_TME (const proc_t **P, const proc_t **Q)
{
@@ -831,6 +835,8 @@
return 1;
case 0:
return 1;
+ case 'e':
+ return 1;
case 'U':
if (pp->ruid == selection_uid) return 1;
if (pp->suid == selection_uid) return 1;
@@ -864,6 +870,69 @@
}
+
+static clusternode_t selection_enode; /* OpenSSI */
+static int good_node(const proc_t *restrict const pp){
+
+ switch(selection_type){
+ case 'p':
+ return 1;
+ case 0:
+ return 1;
+ case 'e':
+ if (pp->enode == selection_enode) return 1;
+ // FALLTHROUGH
+ return 0;
+ case 'U':
+ case 'u':
+ return 1;
+ // FALLTHROUGH
+ default:
+ ; // don't know what it is; find bugs fast
+ }
+ return 0;
+}
+
+// swiped from ps, and ought to be in libproc
+static const char *parse_node(const char *restrict const str, clusternode_t *restrict const ret){
+ static const char invalid_node[] = "Invalid node or node not up";
+ char *endp;
+ unsigned long num;
+ int maxnodes ;
+ int num_nodes;
+ clusternode_t *node_list = NULL;
+ int i = 0;
+
+
+ num = strtoul(str, &endp, 0);
+ if(*endp != '\0'){
+ return invalid_node;
+ }
+
+ if( (maxnodes = cluster_maxnodes()) < 0 )
+ return "cluster_maxnodes() failed";
+
+ /* Allocate space for the list of UP nodes */
+ node_list = (clusternode_t *)malloc(sizeof(clusternode_t) * maxnodes);
+ if (node_list == NULL) {
+ return "Malloc Failed";
+ }
+
+ /* Get the list of UP nodes in the cluster */
+ if ((num_nodes = cluster_membership(NULL, maxnodes, node_list)) < 0) {
+ free(node_list);
+ return "cluster_membership() returned NULL";
+ }
+ for( i = 0; i < num_nodes ; i++ ) {
+ if( node_list[i] == num ) {
+ *ret = num;
+ return 0;
+ }
+ }
+ return invalid_node;
+}
+
+
/*###### Library Alternatives ##########################################*/
/*
@@ -1234,8 +1303,8 @@
L_EITHER - must L_status, else 64-bit math, __udivdi3 on 32-bit !
keys head fmts width scale sort desc lflg
------ ----------- ------- ------ ----- ----- ---------------------- -------- */
- { "AaAa", " PID", " %5u", -1, -1, SF(PID), "Process Id", L_NONE },
- { "BbBb", " PPID", " %5u", -1, -1, SF(PPD), "Parent Process Pid", L_EITHER },
+ { "AaAa", " PID", " %7u", -1, -1, SF(PID), "Process Id", L_NONE },
+ { "BbBb", " PPID", " %7u", -1, -1, SF(PPD), "Parent Process Pid", L_EITHER },
{ "CcQq", " RUSER ", " %-8.8s", -1, -1, SF(URR), "Real user name", L_RUSER },
{ "DdCc", " UID", " %4u", -1, -1, SF(UID), "User Id", L_NONE },
{ "EeDd", " USER ", " %-8.8s", -1, -1, SF(URE), "User Name", L_EUSER },
@@ -1269,6 +1338,7 @@
{ "YyUu", " WCHAN ", " %-9.9s", -1, -1, SF(WCH), "Sleeping in Function", L_stat },
// next entry's special: the 0's will be replaced with '.'!
{ "ZzZz", " Flags ", " %08lx", -1, -1, SF(FLG), "Task Flags <sched.h>", L_stat },
+ { "[{[{", " NODE", " %-5d", -1, -1, SF(NOD), "Execution Node", L_NONE },
#if 0
{ "..Qq", " A", " %4.4s", 4, SK_no, SF(PID), "Accessed Page count", L_stat },
{ "..Nn", " TRS", " %4.4s", 4, SK_Kb, SF(PID), "Code in memory (kb)", L_stat },
@@ -1971,6 +2041,12 @@
int b = 0;
if (fields[i] == f->keys[FT_NEW_fmt])
b = 1;
+
+ if (fields[i] == '[') /* OpenSSI */
+ b = 1;
+ else if (fields[i] == '{') /* OpenSSI */
+ b = 0;
+
if (!f) continue; // hey, should be std_err!
for (p = f->head; ' ' == *p; ++p) // advance past any leading spaces
;
@@ -1986,13 +2062,13 @@
if (xtra) {
putp(Curwin->capclr_rownorm);
while ((p = strchr(xtra, '\n'))) {
- ++i;
PUTT("%s%.*s",
tg2((i / rmax) * cmax, (i % rmax) + yRSVD),
(int)(p - xtra),
xtra
);
xtra = ++p;
+ ++i;
}
}
putp(Caps_off);
@@ -2020,7 +2096,7 @@
if ((i = ft_get_idx(FT_NEW_fmt, c)) < 0) break;
if (((p = strchr(Curwin->rc.fieldscur, Fieldstab[i].keys[FT_NEW_fmt])))
|| ((p = strchr(Curwin->rc.fieldscur, Fieldstab[i].keys[FT_NEW_fmt + 1])))) {
- if (c == Fieldstab[i].keys[FT_NEW_fmt]) p--;
+ if (c == Fieldstab[i].keys[FT_NEW_fmt] || c == '[') p--;
if (('\0' != p[1]) && (p >= Curwin->rc.fieldscur)) {
c = p[0];
p[0] = p[1];
@@ -2043,6 +2119,7 @@
FLD_t *ft;
strcpy(phoney, NUL_FIELDS);
+ if (localview) phoney[strlen(phoney)-1] = '\0';
x = i = Curwin->rc.sortindx;
putp(Cap_clr_scr);
putp(Cap_curs_huge);
@@ -2050,13 +2127,16 @@
p = phoney + i;
if (!(ft = ft_get_ptr(FT_NEW_fmt, *p))) break;
*p = ft->keys[FT_NEW_fmt];
+ if (!localview && *p == '[')
+ *p = '{';
display_fields(phoney, SORT_xtra);
show_special(1, fmtmk(SORT_fields, Cap_home, *p, Curwin->grpname, prompt));
chin(0, &c, 1);
if (!ft_get_ptr(FT_NEW_fmt, c)) break;
+ if (!localview && (c == 'n' || c == 'N' || c == '{' || c == '[')) continue;
i = ft_get_idx(FT_NEW_fmt, c);
*p = ft->keys[FT_NEW_fmt + 1];
- lastkey = c;
+ lastkey = c;
x = i;
}
if ((p = strchr(Curwin->rc.fieldscur, lastkey)))
@@ -2083,6 +2163,8 @@
show_special(1, fmtmk(FIELDS_current, Cap_home, Curwin->rc.fieldscur, Curwin->grpname, prompt));
chin(0, &c, 1);
if (!(f = ft_get_ptr(FT_NEW_fmt, c))) break;
+ if (localview && (c == '[' || c == '{')) continue;
+ if (!localview && (c == 'n' || c == 'N')) continue;
if ((p = strchr(Curwin->rc.fieldscur, f->keys[FT_NEW_fmt])))
*p = f->keys[FT_NEW_fmt + 1];
else if ((p = strchr(Curwin->rc.fieldscur, f->keys[FT_NEW_fmt + 1])))
@@ -2111,6 +2193,12 @@
w = Curwin;
do {
if (!Rc.mode_altscr || CHKw(w, VISIBLE_tsk)) {
+ char *p;
+ if (localview && (p = strchr(w->rc.fieldscur,'[')) != NULL)
+ *p = '{';
+ if (!localview && (p = strchr(w->rc.fieldscur,'N')) != NULL)
+ *p = 'n';
+
// build window's procflags array and establish a tentative maxpflgs
for (i = 0, w->maxpflgs = 0; w->rc.fieldscur[i]; i++) {
if ((f_idx = ft_get_idx(FT_NEW_fmt, w->rc.fieldscur[i])) > - 1)
@@ -2123,6 +2211,11 @@
*(s = w->columnhdr) = '\0';
if (Rc.mode_altscr) s = scat(s, " ");
for (i = 0; i < w->maxpflgs; i++) {
+ if ( localview && (w->procflags[i] == P_NOD))
+ continue;
+ if ( !localview && (w->procflags[i] == P_MEM))
+ continue;
+
h = Fieldstab[w->procflags[i]].head;
// oops, won't fit -- we're outta here...
if (Screen_cols+1 < (int)((s - w->columnhdr) + strlen(h))) break;
@@ -2487,6 +2580,9 @@
// standardized 'smp' errors
static const char err_smp[] = "\aSorry, only 1 cpu detected";
#endif
+ // OpenSSI: 'defaultview mode' errors
+ static const char err_defaultview[] = "\aUnavailable when top is running in defaultview";
+ static const char err_localview[] = "\aUnavailable when top is running in localview";
switch (c) {
case '1':
@@ -2636,11 +2732,17 @@
break;
case 'l':
- TOGw(Curwin, View_LOADAV);
+ if (!localview)
+ show_msg(err_defaultview);
+ else
+ TOGw(Curwin, View_LOADAV);
break;
case 'm':
- TOGw(Curwin, View_MEMORY);
+ if (!localview)
+ show_msg(err_defaultview);
+ else
+ TOGw(Curwin, View_MEMORY);
break;
case 'n':
@@ -2736,6 +2838,28 @@
} while(0);
break;
+ case 'e': /* OpenSSI */
+ if (localview) {
+ show_msg(err_localview);
+ break;
+ }
+ do {
+ const char *errmsg;
+ const char *answer;
+ answer = ask4str("Which node (blank for all)");
+ if (!answer || *answer=='\0' || *answer=='\n' || *answer=='\r' || *answer=='\t' || *answer==' ') {
+ selection_type = 0;
+ selection_enode = -1;
+ break;
+ }
+ errmsg = parse_node(answer, &selection_enode);
+ if (errmsg) {
+ show_msg(errmsg);
+ break;
+ }
+ selection_type = 'e';
+ } while(0);
+ break;
case 'w':
if (Rc.mode_altscr) Curwin = Curwin->prev;
break;
@@ -2945,6 +3069,7 @@
p_table = procs_refresh(p_table, Frames_libflags);
// Display Uptime and Loadavg
+ if (localview) {
if (CHKw(Curwin, View_LOADAV)) {
if (!Rc.mode_altscr) {
show_special(0, fmtmk(LOADAV_line, Myname, sprint_uptime()));
@@ -2960,6 +3085,7 @@
}
Msg_row += 1;
}
+ }
// Display Task and Cpu(s) States
if (CHKw(Curwin, View_STATES)) {
@@ -2974,6 +3100,7 @@
smpcpu = cpus_refresh(smpcpu);
+ if (localview) {
if (CHKw(Curwin, View_CPUSUM)) {
// display just the 1st /proc/stat line
summaryhlp(&smpcpu[Cpu_tot], "Cpu(s):");
@@ -2986,10 +3113,12 @@
summaryhlp(&smpcpu[i], tmp);
}
}
+ }
}
// Display Memory and Swap stats
meminfo();
+ if (localview) {
if (CHKw(Curwin, View_MEMORY)) {
show_special(0, fmtmk(MEMORY_line1
, kb_main_total, kb_main_used, kb_main_free, kb_main_buffers));
@@ -2997,6 +3126,7 @@
, kb_swap_total, kb_swap_used, kb_swap_free, kb_main_cached));
Msg_row += 2;
}
+ }
SETw(Curwin, NEWFRAM_cwo);
return p_table;
@@ -3086,6 +3216,7 @@
MKCOL(p->egroup);
break;
case P_MEM:
+ if (!localview) break;
MKCOL((float)PAGES_TO_KB(p->resident) * 100 / kb_main_total);
break;
case P_NCE:
@@ -3163,6 +3294,10 @@
MKCOL(lookup_wchan(p->wchan, p->XXXID));
}
break;
+ case P_NOD:
+ if (localview) break;
+ MKCOL(p->enode);
+ break;
} /* end: switch 'procflag' */
@@ -3219,7 +3354,7 @@
while ( ppt[i]->tid != -1 && *lscr < Max_lines && (!q->winlines || (lwin <= q->winlines)) ) {
if ((CHKw(q, Show_IDLEPS) || ('S' != ppt[i]->state && 'Z' != ppt[i]->state))
- && good_uid(ppt[i]) ) {
+ && good_uid(ppt[i]) && good_node(ppt[i]) ) { /* OpenSSI */
// Display a process Row
task_show(q, ppt[i]);
(*lscr)++;
@@ -3359,7 +3494,15 @@
if (( getenv("STATSIZE")) && ( atoi(getenv("STATSIZE")) == 1 ))
use_status_vmsize = 1;
-
+
+ /*
+ * OpenSSI : check if I am running in localview mode
+ */
+ localview = check_if_localview(getpid());
+ if (localview == -1) {
+ std_err("error reading /proc/#/localview file\n");
+ }
+
for (;;) {
frame_make();
Index: top.h
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/procps/Attic/top.h,v
retrieving revision 1.1.15.2
retrieving revision 1.1.15.2.2.1
diff -u -d -r1.1.15.2 -r1.1.15.2.2.1
--- top.h 8 Aug 2010 03:33:58 -0000 1.1.15.2
+++ top.h 8 Aug 2010 03:41:06 -0000 1.1.15.2.2.1
@@ -256,7 +256,7 @@
P_CPN, P_CPU, P_TME, P_TM2, P_UTM, P_STM,
P_MEM, P_VRT, P_SWP, P_RES, P_COD, P_DAT, P_SHR,
P_FLT, P_DRT,
- P_STA, P_CMD, P_WCH, P_FLG
+ P_STA, P_CMD, P_WCH, P_FLG, P_NOD
};
@@ -356,13 +356,13 @@
#define RCF_DEPRECATED "Id:a, "
// The default fields displayed and their order,
-#define DEF_FIELDS "AEHIOQTWKNMbcdfgjplrsuvyzX12"
+#define DEF_FIELDS "A[EHIOQTWKNMbcdfgjplrsuvyzX12"
// Pre-configured field groupss
-#define JOB_FIELDS "ABcefgjlrstuvyzMKNHIWOPQDX"
-#define MEM_FIELDS "ANOPQRSTUVbcdefgjlmyzWHIKX"
-#define USR_FIELDS "ABDECGfhijlopqrstuvyzMKNWX"
+#define JOB_FIELDS "A[BcefgjlrstuvyzMKNHIWOPQDX"
+#define MEM_FIELDS "A[NOPQRSTUVbcdefgjlmyzWHIKX"
+#define USR_FIELDS "A[BDECGfhijlopqrstuvyzMKNWX"
// Used by fields_sort, placed here for peace-of-mind
-#define NUL_FIELDS "abcdefghijklm12nopqrstuvwxyz"
+#define NUL_FIELDS "abcdefghijklm12nopqrstuvwxyz{"
// The default values for the local config file
------------------------------------------------------------------------------
This SF.net email is sponsored by
Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev