Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Delta Between Two Patch Sets: src/pkg/runtime/runtime.h

Issue 46970043: code review 46970043: runtime: allocate goroutine ids in batches (Closed)
Left Patch Set: diff -r d5dbdcc7f614 https://dvyukov%40google.com@code.google.com/p/go/ Created 11 years, 2 months ago
Right Patch Set: diff -r 72c0dfd50949 https://dvyukov%40google.com@code.google.com/p/go/ Created 11 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/runtime/proc.c ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 /* 5 /*
6 * basic types 6 * basic types
7 */ 7 */
8 typedef signed char int8; 8 typedef signed char int8;
9 typedef unsigned char uint8; 9 typedef unsigned char uint8;
10 typedef signed short int16; 10 typedef signed short int16;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 typedef struct String String; 59 typedef struct String String;
60 typedef struct FuncVal FuncVal; 60 typedef struct FuncVal FuncVal;
61 typedef struct SigTab SigTab; 61 typedef struct SigTab SigTab;
62 typedef struct MCache MCache; 62 typedef struct MCache MCache;
63 typedef struct FixAlloc FixAlloc; 63 typedef struct FixAlloc FixAlloc;
64 typedef struct Iface Iface; 64 typedef struct Iface Iface;
65 typedef struct Itab Itab; 65 typedef struct Itab Itab;
66 typedef struct InterfaceType InterfaceType; 66 typedef struct InterfaceType InterfaceType;
67 typedef struct Eface Eface; 67 typedef struct Eface Eface;
68 typedef struct Type Type; 68 typedef struct Type Type;
69 typedef struct PtrType PtrType;
69 typedef struct ChanType ChanType; 70 typedef struct ChanType ChanType;
70 typedef struct MapType MapType; 71 typedef struct MapType MapType;
71 typedef struct Defer Defer; 72 typedef struct Defer Defer;
72 typedef struct DeferChunk DeferChunk;
73 typedef struct Panic Panic; 73 typedef struct Panic Panic;
74 typedef struct Hmap Hmap; 74 typedef struct Hmap Hmap;
75 typedef struct Hchan Hchan; 75 typedef struct Hchan Hchan;
76 typedef struct Complex64 Complex64; 76 typedef struct Complex64 Complex64;
77 typedef struct Complex128 Complex128; 77 typedef struct Complex128 Complex128;
78 typedef»struct» WinCall»» WinCall; 78 typedef»struct» LibCall»» LibCall;
79 typedef struct SEH SEH; 79 typedef struct SEH SEH;
80 typedef struct WinCallbackContext WinCallbackContext; 80 typedef struct WinCallbackContext WinCallbackContext;
81 typedef struct Timers Timers; 81 typedef struct Timers Timers;
82 typedef struct Timer Timer; 82 typedef struct Timer Timer;
83 typedef struct GCStats GCStats; 83 typedef struct GCStats GCStats;
84 typedef struct LFNode LFNode; 84 typedef struct LFNode LFNode;
85 typedef struct ParFor ParFor; 85 typedef struct ParFor ParFor;
86 typedef struct ParForThread ParForThread; 86 typedef struct ParForThread ParForThread;
87 typedef struct CgoMal CgoMal; 87 typedef struct CgoMal CgoMal;
88 typedef struct PollDesc PollDesc; 88 typedef struct PollDesc PollDesc;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 { 216 {
217 // the struct must consist of only uint64's, 217 // the struct must consist of only uint64's,
218 // because it is casted to uint64[]. 218 // because it is casted to uint64[].
219 uint64 nhandoff; 219 uint64 nhandoff;
220 uint64 nhandoffcnt; 220 uint64 nhandoffcnt;
221 uint64 nprocyield; 221 uint64 nprocyield;
222 uint64 nosyield; 222 uint64 nosyield;
223 uint64 nsleep; 223 uint64 nsleep;
224 }; 224 };
225 225
226 struct» WinCall 226 struct» LibCall
227 { 227 {
228 void (*fn)(void*); 228 void (*fn)(void*);
229 uintptr n; // number of parameters 229 uintptr n; // number of parameters
230 void* args; // parameters 230 void* args; // parameters
231 uintptr r1; // return values 231 uintptr r1; // return values
232 uintptr r2; 232 uintptr r2;
233 uintptr err; // error number 233 uintptr err; // error number
234 }; 234 };
235 struct SEH 235 struct SEH
236 { 236 {
(...skipping 19 matching lines...) Expand all
256 Defer* defer; 256 Defer* defer;
257 Panic* panic; 257 Panic* panic;
258 Gobuf sched; 258 Gobuf sched;
259 uintptr syscallstack; // if status==Gsyscall, syscallstack = stackbase to use during gc 259 uintptr syscallstack; // if status==Gsyscall, syscallstack = stackbase to use during gc
260 uintptr syscallsp; // if status==Gsyscall, syscallsp = sched.sp to use during gc 260 uintptr syscallsp; // if status==Gsyscall, syscallsp = sched.sp to use during gc
261 uintptr syscallpc; // if status==Gsyscall, syscallpc = sched.pc to use during gc 261 uintptr syscallpc; // if status==Gsyscall, syscallpc = sched.pc to use during gc
262 uintptr syscallguard; // if status==Gsyscall, syscallguard = stackguar d to use during gc 262 uintptr syscallguard; // if status==Gsyscall, syscallguard = stackguar d to use during gc
263 uintptr stackguard; // same as stackguard0, but not set to StackPree mpt 263 uintptr stackguard; // same as stackguard0, but not set to StackPree mpt
264 uintptr stack0; 264 uintptr stack0;
265 uintptr stacksize; 265 uintptr stacksize;
266 G* alllink; // on allg
267 void* param; // passed parameter on wakeup 266 void* param; // passed parameter on wakeup
268 int16 status; 267 int16 status;
269 int64 goid; 268 int64 goid;
269 int64 waitsince; // approx time when the G become blocked
270 int8* waitreason; // if status==Gwaiting 270 int8* waitreason; // if status==Gwaiting
271 G* schedlink; 271 G* schedlink;
272 bool ispanic; 272 bool ispanic;
273 bool issystem; // do not output in stack dump 273 bool issystem; // do not output in stack dump
274 bool isbackground; // ignore in deadlock detector 274 bool isbackground; // ignore in deadlock detector
275 bool preempt; // preemption signal, duplicates stackguard0 = S tackPreempt 275 bool preempt; // preemption signal, duplicates stackguard0 = S tackPreempt
276 int8 raceignore; // ignore race detection events 276 int8 raceignore; // ignore race detection events
277 M* m; // for debuggers, but offset not hard-coded 277 M* m; // for debuggers, but offset not hard-coded
278 M* lockedm; 278 M* lockedm;
279 int32 sig; 279 int32 sig;
280 int32 writenbuf; 280 int32 writenbuf;
281 byte* writebuf; 281 byte* writebuf;
282 DeferChunk* dchunk;
283 DeferChunk* dchunknext;
284 uintptr sigcode0; 282 uintptr sigcode0;
285 uintptr sigcode1; 283 uintptr sigcode1;
286 uintptr sigpc; 284 uintptr sigpc;
287 uintptr gopc; // pc of go statement that created this goroutin e 285 uintptr gopc; // pc of go statement that created this goroutin e
288 uintptr racectx; 286 uintptr racectx;
289 uintptr end[]; 287 uintptr end[];
290 }; 288 };
291 struct M 289 struct M
292 { 290 {
293 G* g0; // goroutine with scheduling stack 291 G* g0; // goroutine with scheduling stack
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 bool racecall; 340 bool racecall;
343 bool needextram; 341 bool needextram;
344 void (*waitunlockf)(Lock*); 342 void (*waitunlockf)(Lock*);
345 void* waitlock; 343 void* waitlock;
346 344
347 uintptr settype_buf[1024]; 345 uintptr settype_buf[1024];
348 uintptr settype_bufsize; 346 uintptr settype_bufsize;
349 347
350 #ifdef GOOS_windows 348 #ifdef GOOS_windows
351 void* thread; // thread handle 349 void* thread; // thread handle
352 » WinCall»wincall; 350 » // these are here because they are too large to be on the stack
351 » // of low-level NOSPLIT functions.
352 » LibCall»libcall;
353 #endif
354 #ifdef GOOS_solaris
355 » int32*» perrno; » // pointer to TLS errno
356 » // these are here because they are too large to be on the stack
357 » // of low-level NOSPLIT functions.
358 » LibCall»libcall;
359 » struct {
360 » » int64» tv_sec;
361 » » int64» tv_nsec;
362 » } ts;
363 » struct {
364 » » uintptr v[6];
365 » } scratch;
353 #endif 366 #endif
354 #ifdef GOOS_plan9 367 #ifdef GOOS_plan9
355 int8* notesig; 368 int8* notesig;
356 byte* errstr; 369 byte* errstr;
357 #endif 370 #endif
358 SEH* seh; 371 SEH* seh;
359 uintptr end[]; 372 uintptr end[];
360 }; 373 };
361 374
362 struct P 375 struct P
363 { 376 {
364 Lock; 377 Lock;
365 378
366 int32 id; 379 int32 id;
367 uint32 status; // one of Pidle/Prunning/... 380 uint32 status; // one of Pidle/Prunning/...
368 P* link; 381 P* link;
369 uint32 schedtick; // incremented on every scheduler call 382 uint32 schedtick; // incremented on every scheduler call
370 uint32 syscalltick; // incremented on every system call 383 uint32 syscalltick; // incremented on every system call
371 M* m; // back-link to associated M (nil if idle) 384 M* m; // back-link to associated M (nil if idle)
372 MCache* mcache; 385 MCache* mcache;
386 Defer* deferpool[5]; // pool of available Defer structs of different sizes (see panic.c)
373 387
374 // Cache of goroutine ids, amortizes accesses to runtime·sched.goidgen. 388 // Cache of goroutine ids, amortizes accesses to runtime·sched.goidgen.
375 uint64 goidcache; 389 uint64 goidcache;
376 uint64 goidcacheend; 390 uint64 goidcacheend;
377 391
378 // Queue of runnable goroutines. 392 // Queue of runnable goroutines.
379 » G**» runq; 393 » uint32» runqhead;
380 » int32» runqhead; 394 » uint32» runqtail;
381 » int32» runqtail; 395 » G*» runq[256];
382 » int32» runqsize;
383 396
384 // Available G's (status == Gdead) 397 // Available G's (status == Gdead)
385 G* gfree; 398 G* gfree;
386 int32 gfreecnt; 399 int32 gfreecnt;
387 400
388 byte pad[64]; 401 byte pad[64];
389 }; 402 };
390 403
391 // The m->locked word holds two pieces of state counting active calls to LockOST hread/lockOSThread. 404 // The m->locked word holds two pieces of state counting active calls to LockOST hread/lockOSThread.
392 // The low bit (LockExternal) is a boolean reporting whether any LockOSThread ca ll is active. 405 // The low bit (LockExternal) is a boolean reporting whether any LockOSThread ca ll is active.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 void (*fun[])(void); 474 void (*fun[])(void);
462 }; 475 };
463 476
464 #ifdef GOOS_windows 477 #ifdef GOOS_windows
465 enum { 478 enum {
466 Windows = 1 479 Windows = 1
467 }; 480 };
468 #else 481 #else
469 enum { 482 enum {
470 Windows = 0 483 Windows = 0
484 };
485 #endif
486 #ifdef GOOS_solaris
487 enum {
488 Solaris = 1
489 };
490 #else
491 enum {
492 Solaris = 0
471 }; 493 };
472 #endif 494 #endif
473 495
474 struct Timers 496 struct Timers
475 { 497 {
476 Lock; 498 Lock;
477 G *timerproc; 499 G *timerproc;
478 bool sleeping; 500 bool sleeping;
479 bool rescheduling; 501 bool rescheduling;
480 Note waitnote; 502 Note waitnote;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 void runtime·intercopy(uintptr, void*, void*); 670 void runtime·intercopy(uintptr, void*, void*);
649 void runtime·nilintercopy(uintptr, void*, void*); 671 void runtime·nilintercopy(uintptr, void*, void*);
650 672
651 /* 673 /*
652 * deferred subroutine calls 674 * deferred subroutine calls
653 */ 675 */
654 struct Defer 676 struct Defer
655 { 677 {
656 int32 siz; 678 int32 siz;
657 bool special; // not part of defer frame 679 bool special; // not part of defer frame
658 bool free; // if special, free when done
659 byte* argp; // where args were copied from 680 byte* argp; // where args were copied from
660 byte* pc; 681 byte* pc;
661 FuncVal* fn; 682 FuncVal* fn;
662 Defer* link; 683 Defer* link;
663 void* args[1]; // padded to actual size 684 void* args[1]; // padded to actual size
664 };
665
666 struct DeferChunk
667 {
668 DeferChunk *prev;
669 uintptr off;
670 }; 685 };
671 686
672 /* 687 /*
673 * panics 688 * panics
674 */ 689 */
675 struct Panic 690 struct Panic
676 { 691 {
677 Eface arg; // argument to panic 692 Eface arg; // argument to panic
678 uintptr stackbase; // g->stackbase in panic 693 uintptr stackbase; // g->stackbase in panic
679 Panic* link; // link to earlier panic 694 Panic* link; // link to earlier panic
(...skipping 20 matching lines...) Expand all
700 void runtime·traceback(uintptr pc, uintptr sp, uintptr lr, G* gp); 715 void runtime·traceback(uintptr pc, uintptr sp, uintptr lr, G* gp);
701 void runtime·tracebackothers(G*); 716 void runtime·tracebackothers(G*);
702 bool runtime·haszeroargs(uintptr pc); 717 bool runtime·haszeroargs(uintptr pc);
703 bool runtime·topofstack(Func*); 718 bool runtime·topofstack(Func*);
704 719
705 /* 720 /*
706 * external data 721 * external data
707 */ 722 */
708 extern String runtime·emptystring; 723 extern String runtime·emptystring;
709 extern uintptr runtime·zerobase; 724 extern uintptr runtime·zerobase;
710 extern» G*» runtime·allg; 725 extern» G**» runtime·allg;
726 extern» uintptr runtime·allglen;
711 extern G* runtime·lastg; 727 extern G* runtime·lastg;
712 extern M* runtime·allm; 728 extern M* runtime·allm;
713 extern P** runtime·allp; 729 extern P** runtime·allp;
714 extern int32 runtime·gomaxprocs; 730 extern int32 runtime·gomaxprocs;
715 extern uint32 runtime·needextram; 731 extern uint32 runtime·needextram;
716 extern uint32 runtime·panicking; 732 extern uint32 runtime·panicking;
717 extern int8* runtime·goos; 733 extern int8* runtime·goos;
718 extern int32 runtime·ncpu; 734 extern int32 runtime·ncpu;
719 extern bool runtime·iscgo; 735 extern bool runtime·iscgo;
720 extern void (*runtime·sysargs)(int32, uint8**); 736 extern void (*runtime·sysargs)(int32, uint8**);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 int32 runtime·funcline(Func*, uintptr, String*); 823 int32 runtime·funcline(Func*, uintptr, String*);
808 int32 runtime·funcarglen(Func*, uintptr); 824 int32 runtime·funcarglen(Func*, uintptr);
809 int32 runtime·funcspdelta(Func*, uintptr); 825 int32 runtime·funcspdelta(Func*, uintptr);
810 int8* runtime·funcname(Func*); 826 int8* runtime·funcname(Func*);
811 int32 runtime·pcdatavalue(Func*, int32, uintptr); 827 int32 runtime·pcdatavalue(Func*, int32, uintptr);
812 void* runtime·stackalloc(uint32); 828 void* runtime·stackalloc(uint32);
813 void runtime·stackfree(void*, uintptr); 829 void runtime·stackfree(void*, uintptr);
814 MCache* runtime·allocmcache(void); 830 MCache* runtime·allocmcache(void);
815 void runtime·freemcache(MCache*); 831 void runtime·freemcache(MCache*);
816 void runtime·mallocinit(void); 832 void runtime·mallocinit(void);
817 void runtime·mprofinit(void);
818 bool runtime·ifaceeq_c(Iface, Iface); 833 bool runtime·ifaceeq_c(Iface, Iface);
819 bool runtime·efaceeq_c(Eface, Eface); 834 bool runtime·efaceeq_c(Eface, Eface);
820 uintptr runtime·ifacehash(Iface, uintptr); 835 uintptr runtime·ifacehash(Iface, uintptr);
821 uintptr runtime·efacehash(Eface, uintptr); 836 uintptr runtime·efacehash(Eface, uintptr);
822 void* runtime·malloc(uintptr size); 837 void* runtime·malloc(uintptr size);
823 void runtime·free(void *v); 838 void runtime·free(void *v);
824 void runtime·runpanic(Panic*); 839 void runtime·runpanic(Panic*);
825 uintptr runtime·getcallersp(void*); 840 uintptr runtime·getcallersp(void*);
826 int32 runtime·mcount(void); 841 int32 runtime·mcount(void);
827 int32 runtime·gcount(void); 842 int32 runtime·gcount(void);
(...skipping 18 matching lines...) Expand all
846 void runtime·entersyscallblock(void); 861 void runtime·entersyscallblock(void);
847 void runtime·exitsyscall(void); 862 void runtime·exitsyscall(void);
848 G* runtime·newproc1(FuncVal*, byte*, int32, int32, void*); 863 G* runtime·newproc1(FuncVal*, byte*, int32, int32, void*);
849 bool runtime·sigsend(int32 sig); 864 bool runtime·sigsend(int32 sig);
850 int32 runtime·callers(int32, uintptr*, int32); 865 int32 runtime·callers(int32, uintptr*, int32);
851 int64 runtime·nanotime(void); 866 int64 runtime·nanotime(void);
852 void runtime·dopanic(int32); 867 void runtime·dopanic(int32);
853 void runtime·startpanic(void); 868 void runtime·startpanic(void);
854 void runtime·freezetheworld(void); 869 void runtime·freezetheworld(void);
855 void runtime·unwindstack(G*, byte*); 870 void runtime·unwindstack(G*, byte*);
856 void» runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp); 871 void» runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp, M *mp);
857 void runtime·resetcpuprofiler(int32); 872 void runtime·resetcpuprofiler(int32);
858 void runtime·setcpuprofilerate(void(*)(uintptr*, int32), int32); 873 void runtime·setcpuprofilerate(void(*)(uintptr*, int32), int32);
859 void runtime·usleep(uint32); 874 void runtime·usleep(uint32);
860 int64 runtime·cputicks(void); 875 int64 runtime·cputicks(void);
861 int64 runtime·tickspersecond(void); 876 int64 runtime·tickspersecond(void);
862 void runtime·blockevent(int64, int32); 877 void runtime·blockevent(int64, int32);
863 extern int64 runtime·blockprofilerate; 878 extern int64 runtime·blockprofilerate;
864 void runtime·addtimer(Timer*); 879 void runtime·addtimer(Timer*);
865 bool runtime·deltimer(Timer*); 880 bool runtime·deltimer(Timer*);
866 G* runtime·netpoll(bool); 881 G* runtime·netpoll(bool);
867 void runtime·netpollinit(void); 882 void runtime·netpollinit(void);
868 int32 runtime·netpollopen(uintptr, PollDesc*); 883 int32 runtime·netpollopen(uintptr, PollDesc*);
869 int32 runtime·netpollclose(uintptr); 884 int32 runtime·netpollclose(uintptr);
870 void runtime·netpollready(G**, PollDesc*, int32); 885 void runtime·netpollready(G**, PollDesc*, int32);
871 uintptr runtime·netpollfd(PollDesc*); 886 uintptr runtime·netpollfd(PollDesc*);
887 void runtime·netpollarmread(uintptr fd);
888 void runtime·netpollarmwrite(uintptr fd);
872 void runtime·crash(void); 889 void runtime·crash(void);
873 void runtime·parsedebugvars(void); 890 void runtime·parsedebugvars(void);
874 void _rt0_go(void); 891 void _rt0_go(void);
875 void* runtime·funcdata(Func*, int32); 892 void* runtime·funcdata(Func*, int32);
876 893
877 #pragma varargck argpos runtime·printf 1 894 #pragma varargck argpos runtime·printf 1
878 #pragma varargck type "c" int32 895 #pragma varargck type "c" int32
879 #pragma varargck type "d" int32 896 #pragma varargck type "d" int32
880 #pragma varargck type "d" uint32 897 #pragma varargck type "d" uint32
881 #pragma varargck type "D" int64 898 #pragma varargck type "D" int64
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 extern float64 runtime·neginf; 1077 extern float64 runtime·neginf;
1061 extern uint64 ·nan; 1078 extern uint64 ·nan;
1062 extern uint64 ·posinf; 1079 extern uint64 ·posinf;
1063 extern uint64 ·neginf; 1080 extern uint64 ·neginf;
1064 #define ISNAN(f) ((f) != (f)) 1081 #define ISNAN(f) ((f) != (f))
1065 1082
1066 enum 1083 enum
1067 { 1084 {
1068 UseSpanType = 1, 1085 UseSpanType = 1,
1069 }; 1086 };
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b