2020-11-17 06:02:45 +01:00
|
|
|
// Copyright 2020 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
// This file references various implementation details from Atmosphere, an open-source firmware for
|
|
|
|
// the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "core/hardware_properties.h"
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
|
|
class KAffinityMask {
|
|
|
|
public:
|
2020-12-05 08:50:32 +01:00
|
|
|
constexpr KAffinityMask() = default;
|
2020-11-17 06:02:45 +01:00
|
|
|
|
2020-12-05 08:50:32 +01:00
|
|
|
[[nodiscard]] constexpr u64 GetAffinityMask() const {
|
2020-11-17 06:02:45 +01:00
|
|
|
return this->mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr void SetAffinityMask(u64 new_mask) {
|
|
|
|
ASSERT((new_mask & ~AllowedAffinityMask) == 0);
|
|
|
|
this->mask = new_mask;
|
|
|
|
}
|
|
|
|
|
2020-12-05 08:50:32 +01:00
|
|
|
[[nodiscard]] constexpr bool GetAffinity(s32 core) const {
|
2021-02-04 21:35:44 +01:00
|
|
|
return (this->mask & GetCoreBit(core)) != 0;
|
2020-11-17 06:02:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
constexpr void SetAffinity(s32 core, bool set) {
|
|
|
|
if (set) {
|
|
|
|
this->mask |= GetCoreBit(core);
|
|
|
|
} else {
|
|
|
|
this->mask &= ~GetCoreBit(core);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr void SetAll() {
|
|
|
|
this->mask = AllowedAffinityMask;
|
|
|
|
}
|
2020-12-05 08:50:32 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
[[nodiscard]] static constexpr u64 GetCoreBit(s32 core) {
|
|
|
|
ASSERT(0 <= core && core < static_cast<s32>(Core::Hardware::NUM_CPU_CORES));
|
|
|
|
return (1ULL << core);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr u64 AllowedAffinityMask = (1ULL << Core::Hardware::NUM_CPU_CORES) - 1;
|
|
|
|
|
|
|
|
u64 mask{};
|
2020-11-17 06:02:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Kernel
|