ccp_msr/
lib.rs

1/*
2 * Copyright 2024 Fluence DAO
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/// This crate is MSR control framework for the archs that have ways to control CPU cache
18/// via MSR registers manipulation, e.g. Linux on x86_64.
19/// For everything else it's a no-op.
20/// Please note there are number of globals that are accessed in the main code.
21
22#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
23#[path = "linux_x86_64/mod.rs"]
24mod msr_impl;
25
26#[cfg(not(all(target_arch = "x86_64", target_os = "linux")))]
27#[path = "other/mod.rs"]
28mod msr_impl;
29
30pub mod state;
31
32use ccp_shared::types::LogicalCoreId;
33
34pub use msr_impl::*;
35
36pub type MSRResult<T> = Result<T, MSRError>;
37
38pub trait MSREnforce {
39    /// Applies auto-chosen MSR preset to current core.
40    fn enforce(&mut self, core_id: LogicalCoreId) -> MSRResult<()>;
41
42    /// Cease applied policy to original presets.
43    fn cease(&self, core_id: LogicalCoreId) -> MSRResult<()>;
44}