Skip to content

Commit e93d74d

Browse files
panosfolintel-lab-lkp
authored andcommitted
rust: task: mark Task methods inline
When you build the kernel using the llvm-18.1.3-rust-1.85.0-x86_64 toolchain provided by kernel.org, the following symbols are generated: $ nm vmlinux | grep ' _R'.*Task | rustfilt ffffffff817b2d30 T <kernel::task::Task>::get_pid_ns ffffffff817b2d50 T <kernel::task::Task>::tgid_nr_ns ffffffff817b2c90 T <kernel::task::Task>::current_pid_ns ffffffff817b2d00 T <kernel::task::Task>::signal_pending ffffffff817b2cc0 T <kernel::task::Task>::uid ffffffff817b2ce0 T <kernel::task::Task>::euid ffffffff817b2c70 T <kernel::task::Task>::current ffffffff817b2d70 T <kernel::task::Task>::wake_up ffffffff817b2db0 T <kernel::task::Task as kernel::types::AlwaysRefCounted>::dec_ref ffffffff817b2d90 T <kernel::task::Task as kernel::types::AlwaysRefCounted>::inc_ref These Rust symbols are trivial wrappers around the C functions get_pid_ns, task_tgid_nr_ns, task_active_pid_ns, signal_pending, uid, euid, get_current, wake_up, get_task_struct and put_task_struct.It doesn't make sense to go through a trivial wrapper for these functions, so mark them inline. After applying this patch, the above command will produce no output. Link: Rust-for-Linux#1145 Signed-off-by: Panagiotis Foliadis <[email protected]>
1 parent 7f0e9ee commit e93d74d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

rust/kernel/task.rs

+10
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl Task {
132132
/// # Safety
133133
///
134134
/// Callers must ensure that the returned object doesn't outlive the current task/thread.
135+
#[inline]
135136
pub unsafe fn current() -> impl Deref<Target = Task> {
136137
struct TaskRef<'a> {
137138
task: &'a Task,
@@ -166,6 +167,7 @@ impl Task {
166167
/// # Safety
167168
///
168169
/// Callers must ensure that the returned object doesn't outlive the current task/thread.
170+
#[inline]
169171
pub unsafe fn current_pid_ns() -> impl Deref<Target = PidNamespace> {
170172
struct PidNamespaceRef<'a> {
171173
task: &'a PidNamespace,
@@ -273,24 +275,28 @@ impl Task {
273275
}
274276

275277
/// Returns the UID of the given task.
278+
#[inline]
276279
pub fn uid(&self) -> Kuid {
277280
// SAFETY: It's always safe to call `task_uid` on a valid task.
278281
Kuid::from_raw(unsafe { bindings::task_uid(self.as_ptr()) })
279282
}
280283

281284
/// Returns the effective UID of the given task.
285+
#[inline]
282286
pub fn euid(&self) -> Kuid {
283287
// SAFETY: It's always safe to call `task_euid` on a valid task.
284288
Kuid::from_raw(unsafe { bindings::task_euid(self.as_ptr()) })
285289
}
286290

287291
/// Determines whether the given task has pending signals.
292+
#[inline]
288293
pub fn signal_pending(&self) -> bool {
289294
// SAFETY: It's always safe to call `signal_pending` on a valid task.
290295
unsafe { bindings::signal_pending(self.as_ptr()) != 0 }
291296
}
292297

293298
/// Returns task's pid namespace with elevated reference count
299+
#[inline]
294300
pub fn get_pid_ns(&self) -> Option<ARef<PidNamespace>> {
295301
// SAFETY: By the type invariant, we know that `self.0` is valid.
296302
let ptr = unsafe { bindings::task_get_pid_ns(self.as_ptr()) };
@@ -306,6 +312,7 @@ impl Task {
306312

307313
/// Returns the given task's pid in the provided pid namespace.
308314
#[doc(alias = "task_tgid_nr_ns")]
315+
#[inline]
309316
pub fn tgid_nr_ns(&self, pidns: Option<&PidNamespace>) -> Pid {
310317
let pidns = match pidns {
311318
Some(pidns) => pidns.as_ptr(),
@@ -319,6 +326,7 @@ impl Task {
319326
}
320327

321328
/// Wakes up the task.
329+
#[inline]
322330
pub fn wake_up(&self) {
323331
// SAFETY: It's always safe to call `signal_pending` on a valid task, even if the task
324332
// running.
@@ -328,11 +336,13 @@ impl Task {
328336

329337
// SAFETY: The type invariants guarantee that `Task` is always refcounted.
330338
unsafe impl crate::types::AlwaysRefCounted for Task {
339+
#[inline]
331340
fn inc_ref(&self) {
332341
// SAFETY: The existence of a shared reference means that the refcount is nonzero.
333342
unsafe { bindings::get_task_struct(self.as_ptr()) };
334343
}
335344

345+
#[inline]
336346
unsafe fn dec_ref(obj: ptr::NonNull<Self>) {
337347
// SAFETY: The safety requirements guarantee that the refcount is nonzero.
338348
unsafe { bindings::put_task_struct(obj.cast().as_ptr()) }

0 commit comments

Comments
 (0)