comparison src/os/linux/vm/os_linux.cpp @ 17810:62c54fcc0a35

Merge
author kvn
date Tue, 25 Mar 2014 17:07:36 -0700
parents bbfbe9b06038 91dc38ae09f3
children 56e7f5560e60
comparison
equal deleted inserted replaced
17809:a433eb716ce1 17810:62c54fcc0a35
1 /* 1 /*
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
106 #ifndef RUSAGE_THREAD 106 #ifndef RUSAGE_THREAD
107 #define RUSAGE_THREAD (1) /* only the calling thread */ 107 #define RUSAGE_THREAD (1) /* only the calling thread */
108 #endif 108 #endif
109 109
110 #define MAX_PATH (2 * K) 110 #define MAX_PATH (2 * K)
111
112 #define MAX_SECS 100000000
111 113
112 // for timer info max values which include all bits 114 // for timer info max values which include all bits
113 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF) 115 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
114 116
115 #define LARGEPAGES_BIT (1 << 6) 117 #define LARGEPAGES_BIT (1 << 6)
2431 bool timedwait(unsigned int sec, int nsec); 2433 bool timedwait(unsigned int sec, int nsec);
2432 private: 2434 private:
2433 sem_t _semaphore; 2435 sem_t _semaphore;
2434 }; 2436 };
2435 2437
2436
2437 Semaphore::Semaphore() { 2438 Semaphore::Semaphore() {
2438 sem_init(&_semaphore, 0, 0); 2439 sem_init(&_semaphore, 0, 0);
2439 } 2440 }
2440 2441
2441 Semaphore::~Semaphore() { 2442 Semaphore::~Semaphore() {
2453 bool Semaphore::trywait() { 2454 bool Semaphore::trywait() {
2454 return sem_trywait(&_semaphore) == 0; 2455 return sem_trywait(&_semaphore) == 0;
2455 } 2456 }
2456 2457
2457 bool Semaphore::timedwait(unsigned int sec, int nsec) { 2458 bool Semaphore::timedwait(unsigned int sec, int nsec) {
2459
2458 struct timespec ts; 2460 struct timespec ts;
2459 unpackTime(&ts, false, (sec * NANOSECS_PER_SEC) + nsec); 2461 // Semaphore's are always associated with CLOCK_REALTIME
2462 os::Linux::clock_gettime(CLOCK_REALTIME, &ts);
2463 // see unpackTime for discussion on overflow checking
2464 if (sec >= MAX_SECS) {
2465 ts.tv_sec += MAX_SECS;
2466 ts.tv_nsec = 0;
2467 } else {
2468 ts.tv_sec += sec;
2469 ts.tv_nsec += nsec;
2470 if (ts.tv_nsec >= NANOSECS_PER_SEC) {
2471 ts.tv_nsec -= NANOSECS_PER_SEC;
2472 ++ts.tv_sec; // note: this must be <= max_secs
2473 }
2474 }
2460 2475
2461 while (1) { 2476 while (1) {
2462 int result = sem_timedwait(&_semaphore, &ts); 2477 int result = sem_timedwait(&_semaphore, &ts);
2463 if (result == 0) { 2478 if (result == 0) {
2464 return true; 2479 return true;
2959 size_t page_sz = os::vm_page_size(); 2974 size_t page_sz = os::vm_page_size();
2960 unsigned pages = size / page_sz; 2975 unsigned pages = size / page_sz;
2961 2976
2962 unsigned char vec[1]; 2977 unsigned char vec[1];
2963 unsigned imin = 1, imax = pages + 1, imid; 2978 unsigned imin = 1, imax = pages + 1, imid;
2964 int mincore_return_value; 2979 int mincore_return_value = 0;
2980
2981 assert(imin <= imax, "Unexpected page size");
2965 2982
2966 while (imin < imax) { 2983 while (imin < imax) {
2967 imid = (imax + imin) / 2; 2984 imid = (imax + imin) / 2;
2968 nbot = ntop - (imid * page_sz); 2985 nbot = ntop - (imid * page_sz);
2969 2986
3831 } 3848 }
3832 return OS_OK ; 3849 return OS_OK ;
3833 } 3850 }
3834 } 3851 }
3835 3852
3836 int os::naked_sleep() { 3853 //
3837 // %% make the sleep time an integer flag. for now use 1 millisec. 3854 // Short sleep, direct OS call.
3838 return os::sleep(Thread::current(), 1, false); 3855 //
3856 // Note: certain versions of Linux CFS scheduler (since 2.6.23) do not guarantee
3857 // sched_yield(2) will actually give up the CPU:
3858 //
3859 // * Alone on this pariticular CPU, keeps running.
3860 // * Before the introduction of "skip_buddy" with "compat_yield" disabled
3861 // (pre 2.6.39).
3862 //
3863 // So calling this with 0 is an alternative.
3864 //
3865 void os::naked_short_sleep(jlong ms) {
3866 struct timespec req;
3867
3868 assert(ms < 1000, "Un-interruptable sleep, short time use only");
3869 req.tv_sec = 0;
3870 if (ms > 0) {
3871 req.tv_nsec = (ms % 1000) * 1000000;
3872 }
3873 else {
3874 req.tv_nsec = 1;
3875 }
3876
3877 nanosleep(&req, NULL);
3878
3879 return;
3839 } 3880 }
3840 3881
3841 // Sleep forever; naked call to OS-specific sleep; use with CAUTION 3882 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
3842 void os::infinite_sleep() { 3883 void os::infinite_sleep() {
3843 while (true) { // sleep forever ... 3884 while (true) { // sleep forever ...
5750 * on the condvar. Contention seen when trying to park implies that someone 5791 * on the condvar. Contention seen when trying to park implies that someone
5751 * is unparking you, so don't wait. And spurious returns are fine, so there 5792 * is unparking you, so don't wait. And spurious returns are fine, so there
5752 * is no need to track notifications. 5793 * is no need to track notifications.
5753 */ 5794 */
5754 5795
5755 #define MAX_SECS 100000000
5756 /* 5796 /*
5757 * This code is common to linux and solaris and will be moved to a 5797 * This code is common to linux and solaris and will be moved to a
5758 * common place in dolphin. 5798 * common place in dolphin.
5759 * 5799 *
5760 * The passed in time value is either a relative time in nanoseconds 5800 * The passed in time value is either a relative time in nanoseconds