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

Commit 1484e5dd authored by Girish's avatar Girish
Browse files

resourcemanager: new implementation of resourcemanager

A new implementation (which inherits from the old implementation)
of the resource manager is added.
The new implementation is enabled only through the feature flag.
Also:
- Additional test cases are added for the new implementation.

Bug: 294886363
Test: atest android.media.misc.cts.ResourceManagerTest
      atest android.media.misc.cts.ResourceManagerMultiTest
      /data/nativetest64/ResourceManagerService_test/ResourceManagerService_test
      /data/nativetest64/ResourceObserverService_test/ResourceObserverService_test
Change-Id: I057bcd0abf8c7a2564a3f77090fdf06ec5915718
parent ce27b94e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ cc_library {
    srcs: [
        "ResourceManagerMetrics.cpp",
        "ResourceManagerService.cpp",
        "ResourceManagerServiceNew.cpp",
        "ResourceObserverService.cpp",
        "ResourceManagerServiceUtils.cpp",
        "ServiceLog.cpp",
@@ -97,6 +98,7 @@ cc_library {
        "libstatssocket",
        "libprotobuf-cpp-lite",
        "libactivitymanager_aidl",
        "aconfig_mediacodec_flags_c_lib",
    ],

    static_libs: [
+15 −0
Original line number Diff line number Diff line
@@ -29,12 +29,16 @@
#include <mediautils/BatteryNotifier.h>
#include <mediautils/ProcessInfo.h>
#include <mediautils/SchedulingPolicyService.h>
#include <com_android_media_codec_flags.h>

#include "IMediaResourceMonitor.h"
#include "ResourceManagerMetrics.h"
#include "ResourceManagerServiceNew.h"
#include "ResourceObserverService.h"
#include "ServiceLog.h"

namespace CodecFeatureFlags = com::android::media::codec::flags;

namespace android {

static void notifyResourceGranted(int pid, const std::vector<MediaResourceParcel>& resources) {
@@ -212,9 +216,20 @@ std::shared_ptr<ResourceManagerService> ResourceManagerService::Create() {
std::shared_ptr<ResourceManagerService> ResourceManagerService::Create(
        const sp<ProcessInfoInterface>& processInfo,
        const sp<SystemCallbackInterface>& systemResource) {
    // If codec importance feature is on, create the refactored implementation.
    if (CodecFeatureFlags::codec_importance()) {
        return ::ndk::SharedRefBase::make<ResourceManagerServiceNew>(processInfo, systemResource);
    }
    return ::ndk::SharedRefBase::make<ResourceManagerService>(processInfo, systemResource);
}

// TEST only function.
std::shared_ptr<ResourceManagerService> ResourceManagerService::CreateNew(
        const sp<ProcessInfoInterface>& processInfo,
        const sp<SystemCallbackInterface>& systemResource) {
    return ::ndk::SharedRefBase::make<ResourceManagerServiceNew>(processInfo, systemResource);
}

ResourceManagerService::~ResourceManagerService() {}

void ResourceManagerService::setObserverService(
+4 −0
Original line number Diff line number Diff line
@@ -186,6 +186,10 @@ private:
    long getPeakConcurrentPixelCount(int pid) const;
    // Get the current concurrent pixel count (associated with the video codecs) for the process.
    long getCurrentConcurrentPixelCount(int pid) const;
    // To create object of type ResourceManagerServiceNew
    static std::shared_ptr<ResourceManagerService> CreateNew(
        const sp<ProcessInfoInterface>& processInfo,
        const sp<SystemCallbackInterface>& systemResource);

    mutable std::mutex mLock;
    sp<ProcessInfoInterface> mProcessInfo;
+107 −0
Original line number Diff line number Diff line
/*
**
** Copyright 2023, 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_NDEBUG 0
#define LOG_TAG "ResourceManagerServiceNew"
#include <utils/Log.h>

#include "ResourceManagerServiceNew.h"

namespace android {

ResourceManagerServiceNew::ResourceManagerServiceNew(
        const sp<ProcessInfoInterface>& processInfo,
        const sp<SystemCallbackInterface>& systemResource) :
  ResourceManagerService(processInfo, systemResource) {}

ResourceManagerServiceNew::~ResourceManagerServiceNew() {}

Status ResourceManagerServiceNew::config(const std::vector<MediaResourcePolicyParcel>& policies) {
    return ResourceManagerService::config(policies);
}

Status ResourceManagerServiceNew::addResource(
        const ClientInfoParcel& clientInfo,
        const std::shared_ptr<IResourceManagerClient>& client,
        const std::vector<MediaResourceParcel>& resources) {
    return ResourceManagerService::addResource(clientInfo, client, resources);
}

Status ResourceManagerServiceNew::removeResource(
        const ClientInfoParcel& clientInfo,
        const std::vector<MediaResourceParcel>& resources) {
    return ResourceManagerService::removeResource(clientInfo, resources);
}

Status ResourceManagerServiceNew::removeClient(const ClientInfoParcel& clientInfo) {
    return ResourceManagerService::removeClient(clientInfo);
}

Status ResourceManagerServiceNew::removeResource(const ClientInfoParcel& clientInfo,
                                                 bool checkValid) {
    return ResourceManagerService::removeResource(clientInfo, checkValid);
}

Status ResourceManagerServiceNew::reclaimResource(
        const ClientInfoParcel& clientInfo,
        const std::vector<MediaResourceParcel>& resources,
        bool* _aidl_return) {
    return ResourceManagerService::reclaimResource(clientInfo, resources, _aidl_return);
}

Status ResourceManagerServiceNew::overridePid(int originalPid, int newPid) {
    return ResourceManagerService::overridePid(originalPid, newPid);
}

Status ResourceManagerServiceNew::overrideProcessInfo(
        const std::shared_ptr<IResourceManagerClient>& client,
        int pid,
        int procState,
        int oomScore) {
    return ResourceManagerService::overrideProcessInfo(client, pid, procState, oomScore);
}

Status ResourceManagerServiceNew::markClientForPendingRemoval(const ClientInfoParcel& clientInfo) {
    return ResourceManagerService::markClientForPendingRemoval(clientInfo);
}

Status ResourceManagerServiceNew::reclaimResourcesFromClientsPendingRemoval(int32_t pid) {
    return ResourceManagerService::reclaimResourcesFromClientsPendingRemoval(pid);
}

Status ResourceManagerServiceNew::notifyClientCreated(const ClientInfoParcel& clientInfo) {
    return ResourceManagerService::notifyClientCreated(clientInfo);
}

Status ResourceManagerServiceNew::notifyClientStarted(const ClientConfigParcel& clientConfig) {
    return ResourceManagerService::notifyClientStarted(clientConfig);
}

Status ResourceManagerServiceNew::notifyClientStopped(const ClientConfigParcel& clientConfig) {
    return ResourceManagerService::notifyClientStopped(clientConfig);
}

Status ResourceManagerServiceNew::notifyClientConfigChanged(
        const ClientConfigParcel& clientConfig) {
    return ResourceManagerService::notifyClientConfigChanged(clientConfig);
}

binder_status_t ResourceManagerServiceNew::dump(int fd, const char** args, uint32_t numArgs) {
    return ResourceManagerService::dump(fd, args, numArgs);
}

} // namespace android
+85 −0
Original line number Diff line number Diff line
/*
**
** Copyright 2023, 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_MEDIA_RESOURCEMANAGERSERVICENEW_H
#define ANDROID_MEDIA_RESOURCEMANAGERSERVICENEW_H

#include "ResourceManagerService.h"

namespace android {

//
// A newer implementation of IResourceManagerService, which
// eventually will replace the older implementation in ResourceManagerService.
//
// To make the transition easier, this implementation overrides the
// private virtual methods from ResourceManagerService.
//
// This implementation is devised to abstract and integrate:
//   - resources into an independent abstraction
//   - resource model as a separate interface (and implementation)
//   - reclaim policy as a separate interface (and implementation)
//
class ResourceManagerServiceNew : public ResourceManagerService {
public:

    explicit ResourceManagerServiceNew(const sp<ProcessInfoInterface>& processInfo,
                                       const sp<SystemCallbackInterface>& systemResource);
    virtual ~ResourceManagerServiceNew();

    // IResourceManagerService interface
    Status config(const std::vector<MediaResourcePolicyParcel>& policies) override;

    Status addResource(const ClientInfoParcel& clientInfo,
                       const std::shared_ptr<IResourceManagerClient>& client,
                       const std::vector<MediaResourceParcel>& resources) override;

    Status removeResource(const ClientInfoParcel& clientInfo,
                          const std::vector<MediaResourceParcel>& resources) override;

    Status removeClient(const ClientInfoParcel& clientInfo) override;

    Status reclaimResource(const ClientInfoParcel& clientInfo,
                           const std::vector<MediaResourceParcel>& resources,
                           bool* _aidl_return) override;

    Status overridePid(int32_t originalPid, int32_t newPid) override;

    Status overrideProcessInfo(const std::shared_ptr<IResourceManagerClient>& client,
                               int32_t pid, int32_t procState, int32_t oomScore) override;

    Status markClientForPendingRemoval(const ClientInfoParcel& clientInfo) override;

    Status reclaimResourcesFromClientsPendingRemoval(int32_t pid) override;

    Status removeResource(const ClientInfoParcel& clientInfo, bool checkValid);

    Status notifyClientCreated(const ClientInfoParcel& clientInfo) override;

    Status notifyClientStarted(const ClientConfigParcel& clientConfig) override;

    Status notifyClientStopped(const ClientConfigParcel& clientConfig) override;

    Status notifyClientConfigChanged(const ClientConfigParcel& clientConfig) override;

    binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
};

// ----------------------------------------------------------------------------
} // namespace android

#endif // ANDROID_MEDIA_RESOURCEMANAGERSERVICENEW_H
Loading