]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: set runtime ncpu on openbsd
authorJoel Sing <jsing@google.com>
Wed, 5 Oct 2011 17:16:43 +0000 (13:16 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 5 Oct 2011 17:16:43 +0000 (13:16 -0400)
Set the runtime ncpu based on the hw.ncpu sysctl.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5191043

src/pkg/runtime/openbsd/386/sys.s
src/pkg/runtime/openbsd/amd64/sys.s
src/pkg/runtime/openbsd/os.h
src/pkg/runtime/openbsd/thread.c

index 3e7c01f8de8a4f4c1ce8a8807e4dee00d2c760f1..c399c91050f49a860870fcffa15bf900cbb11c21 100644 (file)
@@ -269,4 +269,22 @@ TEXT runtime·osyield(SB),7,$-4
        INT     $0x80
        RET
 
+TEXT runtime·sysctl(SB),7,$28
+       LEAL    arg0+0(FP), SI
+       LEAL    4(SP), DI
+       CLD
+       MOVSL                           // arg 1 - name
+       MOVSL                           // arg 2 - namelen
+       MOVSL                           // arg 3 - oldp
+       MOVSL                           // arg 4 - oldlenp
+       MOVSL                           // arg 5 - newp
+       MOVSL                           // arg 6 - newlen
+       MOVL    $202, AX                // sys___sysctl
+       INT     $0x80
+       JCC     3(PC)
+       NEGL    AX
+       RET
+       MOVL    $0, AX
+       RET
+
 GLOBL runtime·tlsoffset(SB),$4
index f1442efcf4d6015c887ad672266bde82b93c2be1..b64868f31416267967d7bab19ad7692fcb401f70 100644 (file)
@@ -235,3 +235,19 @@ TEXT runtime·settls(SB),7,$8
        JCC     2(PC)
        CALL    runtime·notok(SB)
        RET
+
+TEXT runtime·sysctl(SB),7,$0
+       MOVQ    8(SP), DI               // arg 1 - name
+       MOVL    16(SP), SI              // arg 2 - namelen
+       MOVQ    24(SP), DX              // arg 3 - oldp
+       MOVQ    32(SP), R10             // arg 4 - oldlenp
+       MOVQ    40(SP), R8              // arg 5 - newp
+       MOVQ    48(SP), R9              // arg 6 - newlen
+       MOVQ    $202, AX                // sys___sysctl
+       SYSCALL
+       JCC 3(PC)
+       NEGL    AX
+       RET
+       MOVL    $0, AX
+       RET
+
index eba53b7cc2f19db036d0938905cc9c85f6a0858b..4a8a14fb4dfc49de924d28ca48c93197dd11e073 100644 (file)
@@ -8,5 +8,6 @@ void    runtime·sigaltstack(Sigaltstack*, Sigaltstack*);
 void   runtime·sigaction(int32, struct sigaction*, struct sigaction*);
 void   runtime·setitimerval(int32, Itimerval*, Itimerval*);
 void   runtime·setitimer(int32, Itimerval*, Itimerval*);
+int32  runtime·sysctl(uint32*, uint32, byte*, uintptr*, byte*, uintptr);
 
 void   runtime·raisesigpipe(void);
index 909db8cdc97811a080564dc972b9fb905421f112..2972a3cd41d571cb708bd23edf11081dd68c39cf 100644 (file)
@@ -15,6 +15,30 @@ enum
        ENOTSUP = 91,
 };
 
+// From OpenBSD's <sys/sysctl.h>
+#define        CTL_HW  6
+#define        HW_NCPU 3
+
+static int32
+getncpu(void)
+{
+       uint32 mib[2];
+       uint32 out;
+       int32 ret;
+       uintptr nout;
+
+       // Fetch hw.ncpu via sysctl.
+       mib[0] = CTL_HW;
+       mib[1] = HW_NCPU;
+       nout = sizeof out;
+       out = 0;
+       ret = runtime·sysctl(mib, 2, (byte*)&out, &nout, nil, 0);
+       if(ret >= 0)
+               return out;
+       else
+               return 1;
+}
+
 // Basic spinlocks using CAS. We can improve on these later.
 static void
 lock(Lock *l)
@@ -80,10 +104,10 @@ runtime·notewakeup(Note *n)
 }
 
 // From OpenBSD's sys/param.h
-#define RFPROC         (1<<4)  /* change child (else changes curproc) */
-#define RFMEM          (1<<5)  /* share `address space' */
-#define RFNOWAIT       (1<<6)  /* parent need not wait() on child */
-#define RFTHREAD       (1<<13) /* create a thread, not a process */
+#define        RFPROC          (1<<4)  /* change child (else changes curproc) */
+#define        RFMEM           (1<<5)  /* share `address space' */
+#define        RFNOWAIT        (1<<6)  /* parent need not wait() on child */
+#define        RFTHREAD        (1<<13) /* create a thread, not a process */
 
 void
 runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void))
@@ -112,6 +136,7 @@ runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void))
 void
 runtime·osinit(void)
 {
+       runtime·ncpu = getncpu();
 }
 
 void