LEFT | RIGHT |
(no file at all) | |
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 #include "runtime.h" | 5 #include "runtime.h" |
6 #include "arch_GOARCH.h" | 6 #include "arch_GOARCH.h" |
7 | 7 |
8 enum { | 8 enum { |
9 maxround = sizeof(uintptr), | 9 maxround = sizeof(uintptr), |
10 }; | 10 }; |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 { | 351 { |
352 uint32 x; | 352 uint32 x; |
353 | 353 |
354 x = m->fastrand; | 354 x = m->fastrand; |
355 x += x; | 355 x += x; |
356 if(x & 0x80000000L) | 356 if(x & 0x80000000L) |
357 x ^= 0x88888eefUL; | 357 x ^= 0x88888eefUL; |
358 m->fastrand = x; | 358 m->fastrand = x; |
359 return x; | 359 return x; |
360 } | 360 } |
| 361 |
| 362 static Lock ticksLock; |
| 363 static int64 ticks; |
| 364 |
| 365 int64 |
| 366 runtime·tickspersecond(void) |
| 367 { |
| 368 int64 res, t0, t1, c0, c1; |
| 369 |
| 370 res = (int64)runtime·atomicload64((uint64*)&ticks); |
| 371 if(res != 0) |
| 372 return ticks; |
| 373 runtime·lock(&ticksLock); |
| 374 res = ticks; |
| 375 if(res == 0) { |
| 376 t0 = runtime·nanotime(); |
| 377 c0 = runtime·cputicks(); |
| 378 runtime·usleep(100*1000); |
| 379 t1 = runtime·nanotime(); |
| 380 c1 = runtime·cputicks(); |
| 381 if(t1 == t0) |
| 382 t1++; |
| 383 res = (c1-c0)*1000*1000*1000/(t1-t0); |
| 384 if(res == 0) |
| 385 res++; |
| 386 runtime·atomicstore64((uint64*)&ticks, res); |
| 387 } |
| 388 runtime·unlock(&ticksLock); |
| 389 return res; |
| 390 } |
| 391 |
| 392 void |
| 393 runtime∕pprof·runtime_cyclesPerSecond(int64 res) |
| 394 { |
| 395 res = runtime·tickspersecond(); |
| 396 FLUSH(&res); |
| 397 } |
LEFT | RIGHT |