[PATCH 6/10] numactl/libnuma - fix numastat sysfs scanning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



PATCH 6/10 numactl - fix numastat sysfs scanning

Against:  numactl-1.0.3-rc1

On newer kernels, readdir may enumerate the 'node(\d+) subdirs in
the opposite order from older kernels--e.g., node{0,1,2,...} as
opposed to node{N,N-1,N-2,...}.  Not sure when this started 
happening, but RHEL5 [~2.6.18+] behaves as an "older kernel",
while 2.6.25-rc2/3 behave in the "new way".  

Modify numastat to detect when node0 is reported first, and swap
the order so that we continue to report numastats with node0
first--i.e., as leftmost node.

Note:   this still assumes that the nodes are listed in numeric
node id order--either increasing or decreasing.  A more ambitious
rewrite to save the per node stats in arrays indexed by node id
would be more robust to violations of this assumption.  Maybe later?

Signed-off-by:  Lee Schermerhorn <lee.schermerhorn@xxxxxx>

 numastat |   22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

Index: Numactl.d/numastat
===================================================================
--- Numactl.d.orig/numastat	2007-08-16 10:36:23.000000000 -0400
+++ Numactl.d/numastat	2008-02-26 15:44:02.000000000 -0500
@@ -46,16 +46,34 @@ if (! -d "/sys/devices/system/node" ) { 
 
 %stat = (); 
 $title = ""; 
+$mode = 0;
 opendir(NODES, "/sys/devices/system/node") || exit 1;
 foreach $nd (readdir(NODES)) { 
 	next unless $nd =~ /node(\d+)/; 
+	# On newer kernels, readdir may enumerate the 'node(\d+) subdirs
+	# in opposite order from older kernels--e.g., node{0,1,2,...}
+	# as opposed to node{N,N-1,N-2,...}.  Accomodate this by
+	# switching to new mode so that the stats get emitted in
+	# the same order.
+        #print "readdir(NODES) returns $nd\n";
+	if (!$title && $nd =~ /node0/) {
+		$mode = 1;
+	}
 	open(STAT, "/sys/devices/system/node/$nd/numastat") || 
 			die "cannot open $nd: $!\n"; 
-	$title = sprintf("%16s",$nd) . $title;
+	if (! $mode) {
+		$title = sprintf("%16s",$nd) . $title;
+	} else {
+		$title = $title . sprintf("%16s",$nd);
+	}
 	@fields = ();
 	while (<STAT>) { 
 		($name, $val) = split;
-		$stat{$name} = sprintf("%16u", $val) . $stat{$name};
+		if (! $mode) {
+			$stat{$name} = sprintf("%16u", $val) . $stat{$name};
+		} else {
+			$stat{$name} = $stat{$name} . sprintf("%16u", $val);
+		}
 		push(@fields, $name); 
 	} 
 	close STAT; 
--
To unsubscribe from this list: send the line "unsubscribe linux-numa" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]     [Devices]

  Powered by Linux