Changeset 23471
- Timestamp:
- 12/19/07 11:48:57 (12 months ago)
- Location:
- trunk/launchd/src
- Files:
-
- 5 modified
-
launchd.c (modified) (2 diffs)
-
launchd_core_logic.c (modified) (11 diffs)
-
launchd_runtime.c (modified) (7 diffs)
-
launchd_runtime.h (modified) (2 diffs)
-
libvproc_internal.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/launchd/src/launchd.c
r23470 r23471 246 246 launchd_shutdown(void) 247 247 { 248 struct timeval tvnow;248 int64_t now; 249 249 250 250 if (shutdown_in_progress) { … … 265 265 runtime_log_push(); 266 266 267 if (launchd_assumes(gettimeofday(&tvnow, NULL) != -1)) {268 runtime_syslog(LOG_NOTICE, "Shutdown began at: %lu.%06u", tvnow.tv_sec, tvnow.tv_usec); 269 }267 now = runtime_get_wall_time(); 268 269 runtime_syslog(LOG_NOTICE, "Shutdown began at: %lld.%06llu", now / USEC_PER_SEC, now % USEC_PER_SEC); 270 270 271 271 launchd_assert(jobmgr_shutdown(root_jobmgr) != NULL); -
trunk/launchd/src/launchd_core_logic.c
r23470 r23471 24 24 #include <mach/mach.h> 25 25 #include <mach/mach_error.h> 26 #include <mach/mach_time.h>27 26 #include <mach/boolean.h> 28 27 #include <mach/message.h> … … 453 452 static void extract_rcsid_substr(const char *i, char *o, size_t osz); 454 453 static void do_first_per_user_launchd_hack(void); 455 static void do_file_init(void) __attribute__((constructor));456 454 static void do_unmounts(void); 457 455 … … 464 462 static jobmgr_t background_jobmgr; 465 463 static job_t workaround_5477111; 466 static mach_timebase_info_data_t tbi;467 464 468 465 /* process wide globals */ … … 540 537 541 538 job_assumes(j, runtime_kill(j->p, SIGTERM) != -1); 542 j->sent_sigterm_time = mach_absolute_time();539 j->sent_sigterm_time = runtime_get_opaque_time(); 543 540 544 541 if (j->exit_timeout) { … … 2151 2148 2152 2149 if (j->sent_sigterm_time) { 2153 uint64_t td_sec, td_usec, td = (mach_absolute_time() - j->sent_sigterm_time) * tbi.numer / tbi.denom;2150 uint64_t td_sec, td_usec, td = runtime_opaque_time_to_nano(runtime_get_opaque_time() - j->sent_sigterm_time); 2154 2151 2155 2152 td_sec = td / NSEC_PER_SEC; … … 2433 2430 } else if (&j->exit_timeout == ident) { 2434 2431 if (j->sent_sigkill) { 2435 uint64_t td = (mach_absolute_time() - j->sent_sigterm_time) * tbi.numer / tbi.denom;2432 uint64_t td = runtime_opaque_time_to_nano(runtime_get_opaque_time() - j->sent_sigterm_time); 2436 2433 2437 2434 td /= NSEC_PER_SEC; … … 2482 2479 jobmgr_callback(void *obj, struct kevent *kev) 2483 2480 { 2484 struct timeval tvnow;2485 2481 jobmgr_t jm = obj; 2486 2482 job_t ji; … … 2505 2501 runtime_closelog(); /* HACK -- force 'start' time to be set */ 2506 2502 2507 if (getpid() == 1 && jobmgr_assumes(jm, gettimeofday(&tvnow, NULL) != -1)) { 2508 jobmgr_log(jm, LOG_NOTICE, "Anticipatory shutdown began at: %lu.%06u", tvnow.tv_sec, tvnow.tv_usec); 2503 if (getpid() == 1) { 2504 int64_t now = runtime_get_wall_time(); 2505 2506 jobmgr_log(jm, LOG_NOTICE, "Anticipatory shutdown began at: %lld.%06llu", now / USEC_PER_SEC, now % USEC_PER_SEC); 2507 2509 2508 LIST_FOREACH(ji, &root_jobmgr->jobs, sle) { 2510 2509 if (ji->per_user && ji->p) { … … 2563 2562 job_start(job_t j) 2564 2563 { 2565 uint64_t td, tnow = mach_absolute_time();2564 uint64_t td, tnow = runtime_get_opaque_time(); 2566 2565 int spair[2]; 2567 2566 int execspair[2]; … … 2585 2584 /* 2586 2585 * Some users adjust the wall-clock and then expect software to not notice. 2587 * Therefore, launchd must use an absolute clock instead of gettimeofday()2588 * or time()wherever possible.2586 * Therefore, launchd must use an absolute clock instead of the wall clock 2587 * wherever possible. 2589 2588 */ 2590 td = (tnow - j->start_time) * tbi.numer / tbi.denom;2589 td = runtime_opaque_time_to_nano(tnow - j->start_time); 2591 2590 td /= NSEC_PER_SEC; 2592 2591 … … 6738 6737 6739 6738 void 6740 do_file_init(void)6741 {6742 launchd_assert(mach_timebase_info(&tbi) == 0);6743 6744 }6745 6746 void6747 6739 do_unmounts(void) 6748 6740 { -
trunk/launchd/src/launchd_runtime.c
r23470 r23471 34 34 #include <mach/host_info.h> 35 35 #include <mach/mach_host.h> 36 #include <mach/mach_time.h> 36 37 #include <mach/exception.h> 37 38 #include <sys/types.h> … … 110 111 static void logmsg_remove(struct logmsg_s *lm); 111 112 113 static void do_file_init(void) __attribute__((constructor)); 114 static mach_timebase_info_data_t tbi; 112 115 113 116 static const int sigigns[] = { SIGHUP, SIGINT, SIGPIPE, SIGALRM, SIGTERM, … … 1210 1213 data_off = lm->data; 1211 1214 1212 l aunchd_assumes(gettimeofday(&lm->when, NULL) != -1);1215 lm->when = runtime_get_wall_time(); 1213 1216 lm->from_pid = attr->from_pid; 1214 1217 lm->about_pid = attr->about_pid; … … 1308 1311 { 1309 1312 static pthread_mutex_t ourlock = PTHREAD_MUTEX_INITIALIZER; 1310 static struct timeval shutdown_start; 1311 struct timeval tvd; 1313 static int64_t shutdown_start, log_delta; 1312 1314 mach_msg_type_number_t outvalCnt; 1313 1315 struct logmsg_s *lm; … … 1330 1332 } 1331 1333 1332 if (shutdown_start .tv_sec== 0) {1333 gettimeofday(&shutdown_start, NULL);1334 if (shutdown_start == 0) { 1335 shutdown_start = runtime_get_wall_time(); 1334 1336 launchd_log_vm_stats(); 1335 1337 } … … 1350 1352 1351 1353 while ((lm = STAILQ_FIRST(&logmsg_queue))) { 1352 timersub(&lm->when, &shutdown_start, &tvd); 1353 1354 /* don't ask */ 1355 if (tvd.tv_sec < 0) { 1356 tvd.tv_sec = 0; 1357 tvd.tv_usec = 0; 1358 } 1359 1360 fprintf(ourlogfile, "%3ld.%06d%6u %-40s%6u %-40s %s\n", tvd.tv_sec, tvd.tv_usec, 1354 log_delta = lm->when - shutdown_start; 1355 1356 fprintf(ourlogfile, "%8lld%6u %-40s%6u %-40s %s\n", log_delta, 1361 1357 lm->from_pid, lm->from_name, lm->about_pid, lm->about_name, lm->msg); 1362 1358 … … 1551 1547 return (apple_internal_logging == 0); 1552 1548 } 1549 1550 int64_t 1551 runtime_get_wall_time(void) 1552 { 1553 struct timeval tv; 1554 int64_t r; 1555 1556 launchd_assumes(gettimeofday(&tv, NULL) != -1); 1557 1558 r = tv.tv_sec; 1559 r *= USEC_PER_SEC; 1560 r += tv.tv_usec; 1561 1562 return r; 1563 } 1564 1565 uint64_t 1566 runtime_get_opaque_time(void) 1567 { 1568 return mach_absolute_time(); 1569 } 1570 1571 uint64_t 1572 runtime_opaque_time_to_nano(uint64_t o) 1573 { 1574 #if defined(__i386__) 1575 if (unlikely(tbi.numer != tbi.denom)) { 1576 #elif defined(__ppc__) 1577 if (likely(tbi.numer != tbi.denom)) { 1578 #else 1579 if (tbi.numer != tbi.denom) { 1580 #endif 1581 if (o < INT32_MAX) { 1582 o *= tbi.numer; 1583 o /= tbi.denom; 1584 } else { 1585 double d = o; 1586 d *= tbi.numer; 1587 d /= tbi.denom; 1588 o = d; 1589 } 1590 } 1591 1592 return o; 1593 } 1594 1595 void 1596 do_file_init(void) 1597 { 1598 launchd_assert(mach_timebase_info(&tbi) == 0); 1599 } 1600 -
trunk/launchd/src/launchd_runtime.h
r23470 r23471 71 71 #endif 72 72 73 #define likely(x) __builtin_expect((bool)(x), true) 74 #define unlikely(x) __builtin_expect((bool)(x), false) 73 75 74 76 struct ldcred { … … 152 154 void runtime_log_push(void); 153 155 156 int64_t runtime_get_wall_time(void); 157 uint64_t runtime_get_opaque_time(void); 158 uint64_t runtime_opaque_time_to_nano(uint64_t o); 159 154 160 155 161 kern_return_t launchd_set_bport(mach_port_t name); -
trunk/launchd/src/libvproc_internal.h
r23297 r23471 60 60 struct logmsg_s { 61 61 STAILQ_ENTRY(logmsg_s) sqe; 62 struct timevalwhen;62 int64_t when; 63 63 pid_t from_pid; 64 64 pid_t about_pid;

