Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,14 @@ jumbo_component("base") {
sources += [ "time/time_android.cc" ]
}

# Distributed chromium
if (enable_castanets) {
sources += [
"distributed_chromium_util.cc",
"distributed_chromium_util.h",
]
}

if (!use_glib) {
sources -= [
"message_loop/message_pump_glib.cc",
Expand Down
6 changes: 2 additions & 4 deletions base/base_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,8 @@ const char kEnableThreadInstructionCount[] = "enable-thread-instruction-count";
#endif

#if defined(CASTANETS)
const char kEnableForking[] = "enable-forking";

// Specify distributed chrome server address.
const char kServerAddress[] = "server-address";
// Enable features for distributed chromium.
const char kEnableCastanets[] = "enable-castanets";

const char kTcpLaunchTimeout[] = "tcp-launch-timeout";

Expand Down
3 changes: 1 addition & 2 deletions base/base_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ extern const char kEnableThreadInstructionCount[];
#endif

#if defined(CASTANETS)
extern const char kEnableForking[];
extern const char kServerAddress[];
extern const char kEnableCastanets[];
extern const char kTcpLaunchTimeout[];
extern const char kSecureConnection[];
#endif
Expand Down
30 changes: 30 additions & 0 deletions base/distributed_chromium_util.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2020 Samsung Electronics. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/distributed_chromium_util.h"

#include "base/base_switches.h"
#include "base/command_line.h"

namespace base {

bool Castanets::IsEnabled() {
return (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableCastanets))
? true
: false;
}

std::string Castanets::ServerAddress() {
std::string server_address;
base::CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kEnableCastanets)) {
server_address =
command_line->GetSwitchValueASCII(switches::kEnableCastanets);
}

return server_address;
}

} // namespace base
22 changes: 22 additions & 0 deletions base/distributed_chromium_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2020 Samsung Electronics. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_DISTRIBUTED_CHROMIUM_H_
#define BASE_DISTRIBUTED_CHROMIUM_H_

#include <stddef.h>
#include <string>

#include "base/base_export.h"

namespace base {
class BASE_EXPORT Castanets {
public:
static bool IsEnabled();
static std::string ServerAddress();
};

} // namespace base

#endif // BASE_DISTRIBUTED_CHROMIUM_H_
4 changes: 2 additions & 2 deletions base/memory/platform_shared_memory_region_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#if defined(CASTANETS)
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/distributed_chromium_util.h"
#endif

#if defined(OS_ANDROID) && defined(CASTANETS)
Expand Down Expand Up @@ -173,8 +174,7 @@ PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Duplicate() const {
bool PlatformSharedMemoryRegion::ConvertToReadOnly() {

#if defined(CASTANETS)
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableForking)) {
if (base::Castanets::IsEnabled()) {
mode_ = Mode::kReadOnly;
return true;
}
Expand Down
25 changes: 18 additions & 7 deletions base/memory/shared_memory_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#endif // BUILDFLAG(ENABLE_BASE_TRACING)

#if defined(CASTANETS)
#include "base/distributed_chromium_util.h"
#include "base/logging.h"
#include "base/memory/castanets_memory_mapping.h"
#include "base/memory/castanets_memory_syncer.h"
Expand Down Expand Up @@ -105,11 +106,13 @@ void SharedMemoryTracker::IncrementMemoryUsage(
UsageInfo(mapping.mapped_size(), mapping.guid()));

#if defined(CASTANETS)
AutoGuidLock guid_lock(mapping.guid());
AddMapping(mapping.guid(), mapping.mapped_size(), mapping.raw_memory_ptr());
// The shared memory corresponding to the guid began to be used somewhere.
// Therefore delete the holder if it exists.
RemoveHolder(mapping.guid());
if (base::Castanets::IsEnabled()) {
AutoGuidLock guid_lock(mapping.guid());
AddMapping(mapping.guid(), mapping.mapped_size(), mapping.raw_memory_ptr());
// The shared memory corresponding to the guid began to be used somewhere.
// Therefore delete the holder if it exists.
RemoveHolder(mapping.guid());
}
#endif
}

Expand All @@ -119,14 +122,19 @@ void SharedMemoryTracker::DecrementMemoryUsage(
DCHECK(usages_.find(mapping.raw_memory_ptr()) != usages_.end());
usages_.erase(mapping.raw_memory_ptr());
#if defined(CASTANETS)
AutoGuidLock guid_lock(mapping.guid());
RemoveMapping(mapping.guid(), mapping.raw_memory_ptr());
if (base::Castanets::IsEnabled()) {
AutoGuidLock guid_lock(mapping.guid());
RemoveMapping(mapping.guid(), mapping.raw_memory_ptr());
}
#endif
}

#if defined(CASTANETS)
void SharedMemoryTracker::AddMapping(const UnguessableToken &guid, size_t size,
void *ptr) {
if (!base::Castanets::IsEnabled())
return;

AutoLock hold(mapping_lock_);
auto it = mappings_.find(guid);
if (it == mappings_.end()) {
Expand All @@ -149,6 +157,9 @@ void SharedMemoryTracker::AddMapping(const UnguessableToken &guid, size_t size,

void SharedMemoryTracker::RemoveMapping(const UnguessableToken &guid,
void *ptr) {
if (!base::Castanets::IsEnabled())
return;

AutoLock hold(mapping_lock_);
auto it = mappings_.find(guid);
CHECK(it != mappings_.end());
Expand Down
8 changes: 6 additions & 2 deletions base/process/kill_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include "base/threading/platform_thread.h"
#include "build/build_config.h"

#if defined(CASTANETS)
#include "base/distributed_chromium_util.h"
#endif

namespace base {

namespace {
Expand All @@ -30,7 +34,7 @@ TerminationStatus GetTerminationStatusImpl(ProcessHandle handle,
DCHECK(exit_code);

#if defined(CASTANETS)
if (handle == kCastanetsProcessHandle) {
if (base::Castanets::IsEnabled() && (handle == kCastanetsProcessHandle)) {
*exit_code = 0;
return TERMINATION_STATUS_NORMAL_TERMINATION;
}
Expand Down Expand Up @@ -99,7 +103,7 @@ TerminationStatus GetTerminationStatus(ProcessHandle handle, int* exit_code) {
TerminationStatus GetKnownDeadTerminationStatus(ProcessHandle handle,
int* exit_code) {
#if defined(CASTANETS)
if (handle == kCastanetsProcessHandle)
if (base::Castanets::IsEnabled() && (handle == kCastanetsProcessHandle))
return GetTerminationStatusImpl(handle, true /* can_block */, exit_code);
#endif
bool result = kill(handle, SIGKILL) == 0;
Expand Down
15 changes: 10 additions & 5 deletions base/process/process_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include "base/test/clang_profiling.h"
#endif

#if defined(CASTANETS)
#include "base/distributed_chromium_util.h"
#endif

namespace {

#if !defined(OS_NACL_NONSFI)
Expand Down Expand Up @@ -188,7 +192,8 @@ bool WaitForExitWithTimeoutImpl(base::ProcessHandle handle,
base::TimeDelta timeout) {

#if defined(CASTANETS)
if (handle < base::kCastanetsProcessHandle) {
if (base::Castanets::IsEnabled() &&
(handle < base::kCastanetsProcessHandle)) {
*exit_code = -1;
return true;
}
Expand Down Expand Up @@ -292,7 +297,7 @@ void Process::TerminateCurrentProcessImmediately(int exit_code) {

bool Process::IsValid() const {
#if defined(CASTANETS)
if (process_ < kCastanetsProcessHandle)
if (base::Castanets::IsEnabled() && (process_ < kCastanetsProcessHandle))
return true;
#endif
return process_ != kNullProcessHandle;
Expand All @@ -311,7 +316,7 @@ Process Process::Duplicate() const {

ProcessId Process::Pid() const {
#if defined(CASTANETS)
if (process_ < kCastanetsProcessHandle)
if (base::Castanets::IsEnabled() && (process_ < kCastanetsProcessHandle))
return kCastanetsProcessId;
#endif
DCHECK(IsValid());
Expand All @@ -332,7 +337,7 @@ void Process::Close() {
#if !defined(OS_NACL_NONSFI)
bool Process::Terminate(int exit_code, bool wait) const {
#if defined(CASTANETS)
if (process_ < kCastanetsProcessHandle) {
if (base::Castanets::IsEnabled() && (process_ < kCastanetsProcessHandle)) {
// TODO(hw1008.kim): We have to send exit_code to the remote child process?
return true;
}
Expand Down Expand Up @@ -403,7 +408,7 @@ bool Process::SetProcessBackgrounded(bool value) {

int Process::GetPriority() const {
#if defined(CASTANETS)
if (process_ < kCastanetsProcessHandle)
if (base::Castanets::IsEnabled() && (process_ < kCastanetsProcessHandle))
return 0; // The default priority is 0
#endif
DCHECK(IsValid());
Expand Down
6 changes: 4 additions & 2 deletions cc/raster/one_copy_raster_buffer_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#if defined(CASTANETS)
#include "base/command_line.h"
#include "base/distributed_chromium_util.h"
#include "mojo/public/cpp/system/sync.h"
#endif

Expand Down Expand Up @@ -341,8 +342,9 @@ void OneCopyRasterBufferProvider::PlaybackToStagingBuffer(
raster_source, raster_full_rect, playback_rect, transform,
dst_color_space, /*gpu_compositing=*/true, playback_settings);
#if defined(CASTANETS)
if (std::string("renderer") ==
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type")) {
if (base::Castanets::IsEnabled() &&
(std::string("renderer") ==
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type"))) {
mojo::SyncSharedMemory2d(
buffer->CloneHandle().region.GetGUID(), staging_buffer->size.width(),
staging_buffer->size.height(),
Expand Down
31 changes: 17 additions & 14 deletions cc/raster/staging_buffer_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,33 @@
#include "third_party/khronos/GLES2/gl2ext.h"
#include "ui/gfx/gpu_memory_buffer.h"

#if defined(CASTANETS)
#include "base/distributed_chromium_util.h"
#endif

using base::trace_event::MemoryAllocatorDump;
using base::trace_event::MemoryAllocatorDumpGuid;
using base::trace_event::MemoryDumpLevelOfDetail;

namespace cc {
namespace {

#if !defined(CASTANETS)
// Delay between checking for query result to be available.
const int kCheckForQueryResultAvailableTickRateMs = 1;

// Number of attempts to allow before we perform a check that will wait for
// query to complete.
const int kMaxCheckForQueryResultAvailableAttempts = 256;
#endif

// Delay before a staging buffer might be released.
const int kStagingBufferExpirationDelayMs = 1000;

#if !defined(CASTANETS)
bool CheckForQueryResult(gpu::raster::RasterInterface* ri, GLuint query_id) {
DCHECK(query_id);
GLuint complete = 1;
ri->GetQueryObjectuivEXT(query_id, GL_QUERY_RESULT_AVAILABLE_EXT, &complete);
return !!complete;
}
#endif

void WaitForQueryResult(gpu::raster::RasterInterface* ri, GLuint query_id) {
TRACE_EVENT0("cc", "WaitForQueryResult");
Expand All @@ -55,8 +55,9 @@ void WaitForQueryResult(gpu::raster::RasterInterface* ri, GLuint query_id) {
#if defined(CASTANETS)
// FIXME: Skip this region because shared memory of query result
// is not being syncronized.
return;
#else
if (base::Castanets::IsEnabled())
return;
#endif

int attempts_left = kMaxCheckForQueryResultAvailableAttempts;
while (attempts_left--) {
Expand All @@ -73,7 +74,6 @@ void WaitForQueryResult(gpu::raster::RasterInterface* ri, GLuint query_id) {

GLuint result = 0;
ri->GetQueryObjectuivEXT(query_id, GL_QUERY_RESULT_EXT, &result);
#endif
}

} // namespace
Expand Down Expand Up @@ -265,14 +265,17 @@ std::unique_ptr<StagingBuffer> StagingBufferPool::AcquireStagingBuffer(
while (!busy_buffers_.empty()) {
#if defined(CASTANETS)
// FIXME: Fall-back to glFinish because QueryResult isnt handled.
ri->Finish();
#else
// Early out if query isn't used, or if query isn't complete yet. Query is
// created in OneCopyRasterBufferProvider::CopyOnWorkerThread().
if (!busy_buffers_.front()->query_id ||
!CheckForQueryResult(ri, busy_buffers_.front()->query_id))
break;
if (base::Castanets::IsEnabled()) {
ri->Finish();
} else
#endif
{
// Early out if query isn't used, or if query isn't complete yet. Query
// is created in OneCopyRasterBufferProvider::CopyOnWorkerThread().
if (!busy_buffers_.front()->query_id ||
!CheckForQueryResult(ri, busy_buffers_.front()->query_id))
break;
}
MarkStagingBufferAsFree(busy_buffers_.front().get());
free_buffers_.push_back(PopFront(&busy_buffers_));
}
Expand Down
6 changes: 4 additions & 2 deletions cc/tiles/tile_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#if defined(CASTANETS)
#include "base/command_line.h"
#include "base/distributed_chromium_util.h"
#include "mojo/public/cpp/system/sync.h"
#endif // defined(CASTANETS)

Expand Down Expand Up @@ -133,8 +134,9 @@ class RasterTaskImpl : public TileTask {
raster_transform_, playback_settings_, url_);

#if defined(CASTANETS)
if (std::string("renderer") ==
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type")) {
if (base::Castanets::IsEnabled() &&
(std::string("renderer") ==
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type"))) {
ResourcePool::SoftwareBacking* sw_backing = resource_.software_backing();
if (sw_backing) {
int bytes_per_pixel = BitsPerPixel(resource_.format()) / 8;
Expand Down
Loading