Major re-factor of the common_time (formally aah_timesrv) service in preparation for up-integration into Android master. This work includes bug fixes, new features, and general code cleanup. High points are listed below. + CommonClock interface has been enhanced to allow querying of many more low level synchronization details; mostly for debugging, but in theory useful to an application as well. + CommonTimeConfig interface has been implemented. This allows a management process to configure a number of different parameters (many of them new) to control the behavior of the common_time service. Most importantly, the time service can be bound to a specific network interface and should only operate on that interface an no others. + Enhance log messages to be more useful in determining what the time service state machine is doing and why. + Enhance information provided by dumpsys to provide many more details about the quality of time sync and the network conditions which gave rise to the current quality conditions. Features, features, features.... + Add a feature which lets the high level choose a different master election endpoint so that multiple time synchronization domains can co-exist on the same subnet (mostly to support a potential use case of multiple home domains in a multiple dwelling environment like a hotel, dormitory or apartment complex). + Add a feature which lets the high level assign a 64-bit group ID which allows partitioning of time synchronization domains even when the master election endpoint is shared (as it might be if broadcast is being used instead of multicast) + Add an auto-disable feature which lets the time service drop into network-less mode when there are no active clients of the common_time service in the device. Mostly for phones, this allows phones to not consume network/battery resources when they don't need to maintain common time. + Add a feature which lets the high level choose the priority of the common_time service in the master election protocol. This allows high level decisions about things like mobile vs non-mobile, wired ethernet vs WiFi to affect who ends up with the job of master on a given network. Priority overrides at the low level also allow clients coming in from network-less mode to lower their effective priority as they join a new network so as to not disrupt any stable long-running timeline which may already be active on the network. + Add the ability to control some of the core parameters of the time sync service which effect network load (like the sync polling interval and the master announce interval) Change-Id: I71af15a83cfa5ef0417b406928967fb9e02f55c6
91 lines
3.7 KiB
C++
91 lines
3.7 KiB
C++
/*
|
|
* Copyright (C) 2011 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include <common_time/ICommonClock.h>
|
|
|
|
#ifndef ANDROID_COMMON_CLOCK_SERVICE_H
|
|
#define ANDROID_COMMON_CLOCK_SERVICE_H
|
|
|
|
namespace android {
|
|
|
|
class CommonTimeServer;
|
|
|
|
class CommonClockService : public BnCommonClock,
|
|
public android::IBinder::DeathRecipient {
|
|
public:
|
|
static sp<CommonClockService> instantiate(CommonTimeServer& timeServer);
|
|
|
|
virtual status_t dump(int fd, const Vector<String16>& args);
|
|
|
|
virtual status_t isCommonTimeValid(bool* valid, uint32_t *timelineID);
|
|
virtual status_t commonTimeToLocalTime(int64_t common_time,
|
|
int64_t* local_time);
|
|
virtual status_t localTimeToCommonTime(int64_t local_time,
|
|
int64_t* common_time);
|
|
virtual status_t getCommonTime(int64_t* common_time);
|
|
virtual status_t getCommonFreq(uint64_t* freq);
|
|
virtual status_t getLocalTime(int64_t* local_time);
|
|
virtual status_t getLocalFreq(uint64_t* freq);
|
|
virtual status_t getEstimatedError(int32_t* estimate);
|
|
virtual status_t getTimelineID(uint64_t* id);
|
|
virtual status_t getState(ICommonClock::State* state);
|
|
virtual status_t getMasterAddr(struct sockaddr_storage* addr);
|
|
|
|
virtual status_t registerListener(
|
|
const sp<ICommonClockListener>& listener);
|
|
virtual status_t unregisterListener(
|
|
const sp<ICommonClockListener>& listener);
|
|
|
|
void notifyOnTimelineChanged(uint64_t timelineID);
|
|
|
|
private:
|
|
CommonClockService(CommonTimeServer& timeServer)
|
|
: mTimeServer(timeServer) { };
|
|
|
|
virtual void binderDied(const wp<IBinder>& who);
|
|
|
|
CommonTimeServer& mTimeServer;
|
|
|
|
// locks used to synchronize access to the list of registered listeners.
|
|
// The callback lock is held whenever the list is used to perform callbacks
|
|
// or while the list is being modified. The registration lock used to
|
|
// serialize access across registerListener, unregisterListener, and
|
|
// binderDied.
|
|
//
|
|
// The reason for two locks is that registerListener, unregisterListener,
|
|
// and binderDied each call into the core service and obtain the core
|
|
// service thread lock when they call reevaluateAutoDisableState. The core
|
|
// service thread obtains the main thread lock whenever its thread is
|
|
// running, and sometimes needs to call notifyOnTimelineChanged which then
|
|
// obtains the callback lock. If callers of registration functions were
|
|
// holding the callback lock when they called into the core service, we
|
|
// would have a classic A/B, B/A ordering deadlock. To avoid this, the
|
|
// registration functions hold the registration lock for the duration of
|
|
// their call, but hold the callback lock only while they mutate the list.
|
|
// This way, the list's size cannot change (because of the registration
|
|
// lock) during the call into reevaluateAutoDisableState, but the core work
|
|
// thread can still safely call notifyOnTimelineChanged while holding the
|
|
// main thread lock.
|
|
Mutex mCallbackLock;
|
|
Mutex mRegistrationLock;
|
|
|
|
Vector<sp<ICommonClockListener> > mListeners;
|
|
};
|
|
|
|
}; // namespace android
|
|
|
|
#endif // ANDROID_COMMON_CLOCK_SERVICE_H
|