/* Set the time of the specified clock. 
Note that only the  */
int clock_settime(clockid_t clock_id, const struct timespec *tp)
/* Set the time of the specified clock. 
Note that only the  */
int clock_settime(clockid_t clock_id, const struct timespec *tp)
{
	struct timespec base;
	k_spinlock_key_t key;
	if (clock_id != CLOCK_REALTIME) {
		errno = EINVAL;
		return -1;
	}
	if (tp->tv_nsec < 0 || tp->tv_nsec >= NSEC_PER_SEC) {
		errno = EINVAL;
		return -1;
	}
	uint64_t elapsed_nsecs = k_ticks_to_ns_floor64(k_uptime_ticks());
	int64_t delta = (int64_t)NSEC_PER_SEC * tp->tv_sec + tp->tv_nsec
		- elapsed_nsecs;
	base.tv_sec = delta / NSEC_PER_SEC;
	base.tv_nsec = delta % NSEC_PER_SEC;
	key = k_spin_lock(&rt_clock_base_lock);
	rt_clock_base = base;
	k_spin_unlock(&rt_clock_base_lock, key);
	return 0;
}