Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1dc28b79 authored by Glenn Kasten's avatar Glenn Kasten
Browse files

Use scheduling policy service

Change-Id: I3c09da1dc0de5039d0c15ce7fb2bc373fa398712
parent 9e786c78
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -2,6 +2,17 @@ LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
    ISchedulingPolicyService.cpp \
    SchedulingPolicyService.cpp

# FIXME Move this library to frameworks/native
LOCAL_MODULE := libscheduling_policy

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
    AudioBufferProviderSource.cpp   \
    AudioStreamOutSink.cpp          \
@@ -56,6 +67,7 @@ LOCAL_SHARED_LIBRARIES := \
    libpowermanager

LOCAL_STATIC_LIBRARIES := \
    libscheduling_policy \
    libnbaio \
    libcpustats \
    libmedia_helper
@@ -68,6 +80,6 @@ LOCAL_CFLAGS += -DFAST_MIXER_STATISTICS

LOCAL_CFLAGS += -DSTATE_QUEUE_INSTANTIATIONS='"StateQueueInstantiations.cpp"'

LOCAL_CFLAGS += -UHAVE_REQUEST_PRIORITY -UFAST_TRACKS_AT_NON_NATIVE_SAMPLE_RATE -USOAKER
LOCAL_CFLAGS += -DHAVE_REQUEST_PRIORITY -UFAST_TRACKS_AT_NON_NATIVE_SAMPLE_RATE -USOAKER

include $(BUILD_SHARED_LIBRARY)
+4 −0
Original line number Diff line number Diff line
@@ -80,6 +80,10 @@
#include "MonoPipeReader.h"
#include "SourceAudioBufferProvider.h"

#ifdef HAVE_REQUEST_PRIORITY
#include "SchedulingPolicyService.h"
#endif

#ifdef SOAKER
#include "Soaker.h"
#endif
+71 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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.
 */

#define LOG_TAG "SchedulingPolicyService"
//#define LOG_NDEBUG 0

#include <binder/Parcel.h>
#include "ISchedulingPolicyService.h"

namespace android {

// Keep in sync with frameworks/base/core/java/android/os/ISchedulingPolicyService.aidl
enum {
    REQUEST_PRIORITY_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
};

// ----------------------------------------------------------------------

class BpSchedulingPolicyService : public BpInterface<ISchedulingPolicyService>
{
public:
    BpSchedulingPolicyService(const sp<IBinder>& impl)
        : BpInterface<ISchedulingPolicyService>(impl)
    {
    }

    virtual int requestPriority(int32_t pid, int32_t tid, int32_t prio)
    {
        Parcel data, reply;
        data.writeInterfaceToken(ISchedulingPolicyService::getInterfaceDescriptor());
        data.writeInt32(pid);
        data.writeInt32(tid);
        data.writeInt32(prio);
        remote()->transact(REQUEST_PRIORITY_TRANSACTION, data, &reply);
        // fail on exception
        if (reply.readExceptionCode() != 0) return -1;
        return reply.readInt32();
    }
};

IMPLEMENT_META_INTERFACE(SchedulingPolicyService, "android.os.ISchedulingPolicyService");

// ----------------------------------------------------------------------

status_t BnSchedulingPolicyService::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
    switch (code) {
    case REQUEST_PRIORITY_TRANSACTION:
        // Not reached
        return NO_ERROR;
        break;
    default:
        return BBinder::onTransact(code, data, reply, flags);
    }
}

}   // namespace android
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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.
 */

#ifndef ANDROID_ISCHEDULING_POLICY_SERVICE_H
#define ANDROID_ISCHEDULING_POLICY_SERVICE_H

#include <binder/IInterface.h>

namespace android {

class ISchedulingPolicyService : public IInterface
{
public:
    DECLARE_META_INTERFACE(SchedulingPolicyService);

    virtual int         requestPriority(/*pid_t*/int32_t pid, /*pid_t*/int32_t tid,
                                                int32_t prio) = 0;

};

class BnSchedulingPolicyService : public BnInterface<ISchedulingPolicyService>
{
public:
    virtual status_t    onTransact( uint32_t code,
                                    const Parcel& data,
                                    Parcel* reply,
                                    uint32_t flags = 0);
};

}   // namespace android

#endif  // ANDROID_ISCHEDULING_POLICY_SERVICE_H
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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 <binder/IServiceManager.h>
#include <utils/Mutex.h>
#include "ISchedulingPolicyService.h"
#include "SchedulingPolicyService.h"

namespace android {

static sp<ISchedulingPolicyService> sSchedulingPolicyService;
static const String16 _scheduling_policy("scheduling_policy");
static Mutex sMutex;

int requestPriority(pid_t pid, pid_t tid, int32_t prio)
{
    // FIXME merge duplicated code related to service lookup, caching, and error recovery
    sp<ISchedulingPolicyService> sps;
    for (;;) {
        sMutex.lock();
        sps = sSchedulingPolicyService;
        sMutex.unlock();
        if (sps != 0) {
            break;
        }
        sp<IBinder> binder = defaultServiceManager()->checkService(_scheduling_policy);
        if (binder != 0) {
            sps = interface_cast<ISchedulingPolicyService>(binder);
            sMutex.lock();
            sSchedulingPolicyService = sps;
            sMutex.unlock();
            break;
        }
        sleep(1);
    }
    return sps->requestPriority(pid, tid, prio);
}

}   // namespace android
Loading