From 6cef6279c25ea6bfd4ed937d65daf1da6c107fb8 Mon Sep 17 00:00:00 2001
From: "msvensson@pilot.(none)" <>
Date: Sun, 4 May 2008 16:35:16 +0200
Subject: [PATCH] Always set bogomips unless already set Return undef only in
 case kstat works Cpus reported once, but with 'cpu_count' set to the actual
 number

---
 mysql-test/lib/My/SysInfo.pm | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/mysql-test/lib/My/SysInfo.pm b/mysql-test/lib/My/SysInfo.pm
index b764b4548f7..87f768f4866 100644
--- a/mysql-test/lib/My/SysInfo.pm
+++ b/mysql-test/lib/My/SysInfo.pm
@@ -21,7 +21,7 @@ use strict;
 use Carp;
 use My::Platform;
 
-
+use constant DEFAULT_BOGO_MIPS => 2000;
 
 sub _cpuinfo {
   my ($self)= @_;
@@ -59,7 +59,14 @@ sub _cpuinfo {
       }
     }
 
-    push(@{$self->{cpus}}, $cpuinfo);
+    # Make sure bogomips is set to some value
+    $cpuinfo->{bogomips} |= DEFAULT_BOGO_MIPS;
+
+    # Cpus reported once, but with 'cpu_count' set to the actual number
+    my $cpu_count= $cpuinfo->{cpu_count} || 1;
+    for(1..$cpu_count){
+      push(@{$self->{cpus}}, $cpuinfo);
+    }
   }
   $F= undef; # Close file
   return $self;
@@ -71,7 +78,7 @@ sub _kstat {
   while (1){
     my $instance_num= $self->{cpus} ? @{$self->{cpus}} : 0;
     my $list= `kstat -p -m cpu_info -i $instance_num`;
-    my @lines= split('\n', $list) or return undef;
+    my @lines= split('\n', $list) or last; # Break loop
 
     my $cpuinfo= {};
     foreach my $line (@lines)
@@ -82,14 +89,19 @@ sub _kstat {
       $cpuinfo->{$statistic}= $value;
     }
 
-    # Default value, the actual cpu values can be used to decrease it
+    # Default value, the actual cpu values can be used to decrease this
     # on slower cpus
-    $cpuinfo->{bogomips}= 2000;
+    $cpuinfo->{bogomips}= DEFAULT_BOGO_MIPS;
 
     push(@{$self->{cpus}}, $cpuinfo);
   }
 
-  return $self;
+  # At least one cpu should have been found
+  # if this method worked
+  if ( $self->{cpus} ) {
+    return $self;
+  }
+  return undef;
 }
 
 
@@ -122,7 +134,11 @@ sub new {
   }
 
   # Push a dummy cpu
-  push(@{$self->{cpus}}, {bogomips => 2000, model_name => "unknown"});
+  push(@{$self->{cpus}},
+     {
+      bogomips => DEFAULT_BOGO_MIPS,
+      model_name => "unknown",
+     });
 
   return $self;
 }