cpumask_test_and_set_cpu(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… cpumask_test_and_set_cpu β€” from the Kernel API Manual, bestie πŸ’–

okay so picture this: you're deep in the kernel, you've got a cpumask, and you need to check one cpu AND flip it on, all in one go, with zero race conditions. that's this function. she's the atomic queen. slay. πŸ‘‘


✨ NAME ✨

cpumask_test_and_set_cpu β€” atomically test and set a cpu in a cpumask πŸŽ€


🌸 SYNOPSIS 🌸

bool cpumask_test_and_set_cpu (int cpu , struct cpumask *cpumask );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • cpu β€” the cpu number you're checking, and the vibe check on this one is it must be < nr_cpu_ids πŸ’€ (respect the limit, bestie)
  • cpumask β€” the cpumask pointer. that's your bitmap, your little roster of cpus 🫢

🧚 DESCRIPTION 🧚

literally it's a test_and_set_bit wrapper for cpumasks. that's the whole thing, and honestly? iconic. πŸ’…


πŸ”₯ RETURN πŸ”₯

true if cpu was set in the old bitmap of cpumask β€” else it returns false. so you're peeking at the state before the set, not after. iykyk. 😌


πŸ‘‘ SEE ALSO πŸ‘‘

so many friends, one big family reunion, and every single one of them is here πŸŽ‰

and if you wanna read the source yourself (main character behavior honestly), it lives in the kernel file ./include/linux/cpumask.h πŸ“–


ngl the one rule here: cpu has to be < nr_cpu_ids. no cap. don't be out here passing a cpu number that doesn't exist πŸ™ˆ

that's the whole page bestie!! brought to you by ./include/linux, dated October 2026, and this little header goes out to cpumask_test_and_set_cpu(9) β€” atomic, adorable, absolutely ate. periodt. πŸ’œπŸŒΈβœ¨

πŸ“¦ where this page comes from