From c5b0b0ba47703b28f0772382ff1e65eda209db4e Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 2 Jul 2007 02:37:05 +0000 Subject: [PATCH] Add an option (-n ncpus) to specify the number of cpus a virtual kernel should simulate. The virtual kernel must be built with options SMP. 1-32 cpus may be simulated regardless of the number of real cpus. The virtual kernel will create a thread for each cpu. --- share/man/man7/vkernel.7 | 8 +++++++- sys/platform/vkernel/i386/mp.c | 5 ++--- sys/platform/vkernel/include/smp.h | 4 +++- sys/platform/vkernel/platform/init.c | 30 +++++++++++++++++++++++----- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/share/man/man7/vkernel.7 b/share/man/man7/vkernel.7 index e694c6273c..0b20b8be10 100644 --- a/share/man/man7/vkernel.7 +++ b/share/man/man7/vkernel.7 @@ -29,7 +29,7 @@ .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $DragonFly: src/share/man/man7/vkernel.7,v 1.21 2007/06/23 20:52:41 swildner Exp $ +.\" $DragonFly: src/share/man/man7/vkernel.7,v 1.22 2007/07/02 02:37:02 dillon Exp $ .\" .Dd June 14, 2007 .Dt VKERNEL 7 @@ -51,6 +51,7 @@ .Op Fl i Ar file .Op Fl I Ar interface Ns Op Ar :address1 Ns Oo Ar :address2 Oc Ns Oo Ar /netmask Oc .Op Fl m Ar size +.Op Fl n Ar numcpus .Op Fl p Ar file .Op Fl r Ar file .Sh DESCRIPTION @@ -150,6 +151,11 @@ Lowercase versions of and .Cm G are allowed. +.It Fl n Ar numcpus +Specify the number of cpus you wish to emulate. +Up to 32 cpus are supported. +The virtual kernel must be built with options SMP to use this option +and will default to 2 cpus unless otherwise specified. .It Fl p Ar file Specify a file in which to store the process ID. A warning is issued if this file cannot be opened for writing. diff --git a/sys/platform/vkernel/i386/mp.c b/sys/platform/vkernel/i386/mp.c index c86628f473..9f24de1ab6 100644 --- a/sys/platform/vkernel/i386/mp.c +++ b/sys/platform/vkernel/i386/mp.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/platform/vkernel/i386/mp.c,v 1.3 2007/07/01 04:02:33 dillon Exp $ + * $DragonFly: src/sys/platform/vkernel/i386/mp.c,v 1.4 2007/07/02 02:37:03 dillon Exp $ */ @@ -142,8 +142,7 @@ mp_start(void) { int shift; - /* XXX testing 2 cpus */ - ncpus = 2; + ncpus = optcpus; mp_naps = ncpus - 1; diff --git a/sys/platform/vkernel/include/smp.h b/sys/platform/vkernel/include/smp.h index 277cd39394..1bfc088634 100644 --- a/sys/platform/vkernel/include/smp.h +++ b/sys/platform/vkernel/include/smp.h @@ -7,7 +7,7 @@ * ---------------------------------------------------------------------------- * * $FreeBSD: src/sys/i386/include/smp.h,v 1.50.2.5 2001/02/13 22:32:45 tegge Exp $ - * $DragonFly: src/sys/platform/vkernel/include/smp.h,v 1.2 2007/06/18 18:57:13 josepht Exp $ + * $DragonFly: src/sys/platform/vkernel/include/smp.h,v 1.3 2007/07/02 02:37:04 dillon Exp $ * */ @@ -50,6 +50,8 @@ void bootMP (void); /* global data in apic_vector.s */ extern volatile u_int stopped_cpus; +extern int optcpus; /* from main() */ + #if 0 extern volatile u_int started_cpus; diff --git a/sys/platform/vkernel/platform/init.c b/sys/platform/vkernel/platform/init.c index 789c679c9c..a209f7a887 100644 --- a/sys/platform/vkernel/platform/init.c +++ b/sys/platform/vkernel/platform/init.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/platform/vkernel/platform/init.c,v 1.40 2007/06/19 17:25:48 dillon Exp $ + * $DragonFly: src/sys/platform/vkernel/platform/init.c,v 1.41 2007/07/02 02:37:05 dillon Exp $ */ #include @@ -96,6 +96,7 @@ vpte_t *KernelPTD; vpte_t *KernelPTA; /* Warning: Offset for direct VA translation */ u_int cpu_feature; /* XXX */ u_int tsc_present; /* XXX */ +int optcpus; /* number of cpus - see mp_start() */ struct privatespace *CPU_prvspace; @@ -110,7 +111,7 @@ static void init_disk(char *diskExp[], int diskFileNum, enum vkdisk_type type); static void init_netif(char *netifExp[], int netifFileNum); static void writepid( void ); static void cleanpid( void ); -static void usage(const char *ctl); +static void usage(const char *str); static int save_ac; static char **save_av; @@ -140,8 +141,11 @@ main(int ac, char **av) * Process options */ kernel_mem_readonly = 1; +#ifdef SMP + optcpus = 2; +#endif - while ((c = getopt(ac, av, "c:svm:r:e:i:p:I:U")) != -1) { + while ((c = getopt(ac, av, "c:svm:n:r:e:i:p:I:U")) != -1) { switch(c) { case 'e': /* @@ -203,6 +207,21 @@ main(int ac, char **av) } } break; + case 'n': + /* + * This value is set up by mp_start(), don't just + * set ncpus here. + */ +#ifdef SMP + optcpus = strtol(optarg, NULL, 0); + if (optcpus < 1 || optcpus > 32) + usage("Bad ncpus, valid range is 1-32"); +#else + if (strtol(optarg, NULL, 0) != 1) { + usage("You built a UP vkernel, only 1 cpu!"); + } +#endif + case 'p': pid_file = optarg; break; @@ -1077,9 +1096,10 @@ cleanpid( void ) static void -usage(const char *ctl) +usage(const char *str) { - + fprintf(stderr, "%s\n", str); + exit(1); } void -- 2.41.0