Commit ed4303f5 authored by Laís Minchillo's avatar Laís Minchillo Committed by Commit Bot

[aw] Add SetCpuAffinityToLittleCores method

Add a method in AwDebug to set CPU affinity to little cores in WebView.

Bug: 1111789
Change-Id: Iece9bd27d60ec0338da88abf6a69c59dc4268e6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2521612Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarEric Seckler <eseckler@chromium.org>
Commit-Queue: Laís Minchillo <laisminchillo@chromium.org>
Auto-Submit: Laís Minchillo <laisminchillo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826893}
parent 0f543f1d
...@@ -2,14 +2,50 @@ ...@@ -2,14 +2,50 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "android_webview/browser/aw_render_process.h"
#include "android_webview/browser_jni_headers/AwDebug_jni.h" #include "android_webview/browser_jni_headers/AwDebug_jni.h"
#include "android_webview/common/crash_reporter/crash_keys.h" #include "android_webview/common/crash_reporter/crash_keys.h"
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "base/no_destructor.h"
#include "components/crash/core/common/crash_key.h" #include "components/crash/core/common/crash_key.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_process_host_creation_observer.h"
using content::RenderProcessHost;
namespace android_webview { namespace android_webview {
class AwDebugCpuAffinity : public content::RenderProcessHostCreationObserver {
public:
AwDebugCpuAffinity() {
for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
!i.IsAtEnd(); i.Advance()) {
RenderProcessHost* process_host = i.GetCurrentValue();
if (process_host) {
SetAffinityForProcessHost(process_host);
}
}
}
// content::RenderProcessHostCreationObserver:
void OnRenderProcessHostCreated(RenderProcessHost* process_host) override {
SetAffinityForProcessHost(process_host);
}
private:
void SetAffinityForProcessHost(RenderProcessHost* process_host) {
process_host->PostTaskWhenProcessIsReady(base::BindOnce(
&AwRenderProcess::SetCpuAffinityToLittleCores,
base::Unretained(
AwRenderProcess::GetInstanceForRenderProcessHost(process_host))));
}
};
static void JNI_AwDebug_SetCpuAffinityToLittleCores(JNIEnv* env) {
static base::NoDestructor<AwDebugCpuAffinity> aw_debug_cpu_affinity;
}
static void JNI_AwDebug_SetSupportLibraryWebkitVersionCrashKey( static void JNI_AwDebug_SetSupportLibraryWebkitVersionCrashKey(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jstring>& version) { const base::android::JavaParamRef<jstring>& version) {
......
...@@ -66,6 +66,10 @@ void AwRenderProcess::SetJsOnlineProperty(bool network_up) { ...@@ -66,6 +66,10 @@ void AwRenderProcess::SetJsOnlineProperty(bool network_up) {
renderer_remote_->SetJsOnlineProperty(network_up); renderer_remote_->SetJsOnlineProperty(network_up);
} }
void AwRenderProcess::SetCpuAffinityToLittleCores() {
renderer_remote_->SetCpuAffinityToLittleCores();
}
void AwRenderProcess::Ready() { void AwRenderProcess::Ready() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
......
...@@ -34,6 +34,7 @@ class AwRenderProcess : public content::RenderProcessHostObserver, ...@@ -34,6 +34,7 @@ class AwRenderProcess : public content::RenderProcessHostObserver,
void ClearCache(); void ClearCache();
void SetJsOnlineProperty(bool network_up); void SetJsOnlineProperty(bool network_up);
void SetCpuAffinityToLittleCores();
private: private:
void Ready(); void Ready();
......
...@@ -13,4 +13,8 @@ interface Renderer { ...@@ -13,4 +13,8 @@ interface Renderer {
// Adjusts the javascript 'online' property value. // Adjusts the javascript 'online' property value.
SetJsOnlineProperty(bool network_up); SetJsOnlineProperty(bool network_up);
// Set renderer process CPU affinity to little cores. Temporarily added for an
// experiment; to be deleted after its conclusion (https://crbug.com/1111789).
SetCpuAffinityToLittleCores();
}; };
...@@ -38,8 +38,14 @@ public class AwDebug { ...@@ -38,8 +38,14 @@ public class AwDebug {
AwDebugJni.get().setSupportLibraryWebkitVersionCrashKey(version); AwDebugJni.get().setSupportLibraryWebkitVersionCrashKey(version);
} }
@UsedByReflection("")
public static void setCpuAffinityToLittleCores() {
AwDebugJni.get().setCpuAffinityToLittleCores();
}
@NativeMethods @NativeMethods
interface Natives { interface Natives {
void setSupportLibraryWebkitVersionCrashKey(String version); void setSupportLibraryWebkitVersionCrashKey(String version);
void setCpuAffinityToLittleCores();
} }
} }
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "android_webview/renderer/aw_render_thread_observer.h" #include "android_webview/renderer/aw_render_thread_observer.h"
#include "content/public/common/cpu_affinity.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#include "third_party/blink/public/platform/web_cache.h" #include "third_party/blink/public/platform/web_cache.h"
#include "third_party/blink/public/platform/web_network_state_notifier.h" #include "third_party/blink/public/platform/web_network_state_notifier.h"
...@@ -44,4 +45,8 @@ void AwRenderThreadObserver::SetJsOnlineProperty(bool network_up) { ...@@ -44,4 +45,8 @@ void AwRenderThreadObserver::SetJsOnlineProperty(bool network_up) {
blink::WebNetworkStateNotifier::SetOnLine(network_up); blink::WebNetworkStateNotifier::SetOnLine(network_up);
} }
void AwRenderThreadObserver::SetCpuAffinityToLittleCores() {
content::EnforceProcessCpuAffinity(base::CpuAffinityMode::kLittleCoresOnly);
}
} // namespace android_webview } // namespace android_webview
...@@ -30,6 +30,7 @@ class AwRenderThreadObserver : public content::RenderThreadObserver, ...@@ -30,6 +30,7 @@ class AwRenderThreadObserver : public content::RenderThreadObserver,
// mojom::Renderer overrides: // mojom::Renderer overrides:
void ClearCache() override; void ClearCache() override;
void SetJsOnlineProperty(bool network_up) override; void SetJsOnlineProperty(bool network_up) override;
void SetCpuAffinityToLittleCores() override;
void OnRendererAssociatedRequest( void OnRendererAssociatedRequest(
mojo::PendingAssociatedReceiver<mojom::Renderer> receiver); mojo::PendingAssociatedReceiver<mojom::Renderer> receiver);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment