Universal clocksd (#2075)
* universal clocksd * start in manager * remove android include * Apple hacks Co-authored-by: Comma Device <device@comma.ai>pull/2081/head
parent
7956bb6883
commit
e497b95f54
|
@ -302,19 +302,19 @@ SConscript(['selfdrive/controls/lib/longitudinal_mpc_model/SConscript'])
|
|||
|
||||
SConscript(['selfdrive/boardd/SConscript'])
|
||||
SConscript(['selfdrive/proclogd/SConscript'])
|
||||
SConscript(['selfdrive/clocksd/SConscript'])
|
||||
|
||||
SConscript(['selfdrive/loggerd/SConscript'])
|
||||
|
||||
SConscript(['selfdrive/locationd/SConscript'])
|
||||
SConscript(['selfdrive/locationd/models/SConscript'])
|
||||
|
||||
|
||||
if arch == "aarch64":
|
||||
SConscript(['selfdrive/logcatd/SConscript'])
|
||||
SConscript(['selfdrive/sensord/SConscript'])
|
||||
SConscript(['selfdrive/clocksd/SConscript'])
|
||||
else:
|
||||
SConscript(['tools/lib/index_log/SConscript'])
|
||||
|
||||
if arch != "larch64":
|
||||
SConscript(['selfdrive/ui/SConscript'])
|
||||
|
||||
if arch == "x86_64":
|
||||
SConscript(['tools/lib/index_log/SConscript'])
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
Import('env', 'common', 'cereal', 'messaging')
|
||||
env.Program('clocksd.cc', LIBS=['diag', 'time_genoff', common, cereal, messaging, 'capnp', 'zmq', 'kj'])
|
||||
env.Program('clocksd.cc', LIBS=[common, cereal, messaging, 'capnp', 'zmq', 'kj'])
|
||||
|
|
|
@ -1,12 +1,22 @@
|
|||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <sys/time.h>
|
||||
#include <utils/Timers.h>
|
||||
|
||||
#include <cassert>
|
||||
#include "messaging.hpp"
|
||||
#include "common/timing.h"
|
||||
|
||||
// Apple doesn't have timerfd
|
||||
#ifndef __APPLE__
|
||||
#include <sys/timerfd.h>
|
||||
#endif
|
||||
|
||||
#ifdef QCOM
|
||||
namespace {
|
||||
int64_t arm_cntpct() {
|
||||
int64_t v;
|
||||
|
@ -14,13 +24,14 @@ namespace {
|
|||
return v;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
setpriority(PRIO_PROCESS, 0, -13);
|
||||
|
||||
int err = 0;
|
||||
PubMaster pm({"clocks"});
|
||||
|
||||
#ifndef __APPLE__
|
||||
int timerfd = timerfd_create(CLOCK_BOOTTIME, 0);
|
||||
assert(timerfd >= 0);
|
||||
|
||||
|
@ -30,19 +41,26 @@ int main() {
|
|||
spec.it_value.tv_sec = 1;
|
||||
spec.it_value.tv_nsec = 0;
|
||||
|
||||
err = timerfd_settime(timerfd, 0, &spec, 0);
|
||||
int err = timerfd_settime(timerfd, 0, &spec, 0);
|
||||
assert(err == 0);
|
||||
|
||||
uint64_t expirations = 0;
|
||||
while ((err = read(timerfd, &expirations, sizeof(expirations)))) {
|
||||
if (err < 0) break;
|
||||
#else
|
||||
// Just run at 1Hz on apple
|
||||
while (true){
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
#endif
|
||||
|
||||
uint64_t boottime = nanos_since_boot();
|
||||
uint64_t monotonic = nanos_monotonic();
|
||||
uint64_t monotonic_raw = nanos_monotonic_raw();
|
||||
uint64_t wall_time = nanos_since_epoch();
|
||||
|
||||
#ifdef QCOM
|
||||
uint64_t modem_uptime_v = arm_cntpct() / 19200ULL; // 19.2 mhz clock
|
||||
#endif
|
||||
|
||||
capnp::MallocMessageBuilder msg;
|
||||
cereal::Event::Builder event = msg.initRoot<cereal::Event>();
|
||||
|
@ -53,11 +71,15 @@ int main() {
|
|||
clocks.setMonotonicNanos(monotonic);
|
||||
clocks.setMonotonicRawNanos(monotonic_raw);
|
||||
clocks.setWallTimeNanos(wall_time);
|
||||
#ifdef QCOM
|
||||
clocks.setModemUptimeMillis(modem_uptime_v);
|
||||
#endif
|
||||
|
||||
pm.send("clocks", msg);
|
||||
}
|
||||
|
||||
#ifndef __APPLE__
|
||||
close(timerfd);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -239,6 +239,7 @@ car_started_processes = [
|
|||
'proclogd',
|
||||
'ubloxd',
|
||||
'locationd',
|
||||
'clocksd',
|
||||
]
|
||||
|
||||
driver_view_processes = [
|
||||
|
@ -255,7 +256,6 @@ if WEBCAM:
|
|||
if ANDROID:
|
||||
car_started_processes += [
|
||||
'sensord',
|
||||
'clocksd',
|
||||
'gpsd',
|
||||
'dmonitoringmodeld',
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue