Skip to content

Instantly share code, notes, and snippets.

@plusk01
plusk01 / taskset_example.md
Last active February 14, 2023 20:43
Understanding CPU affinity with taskset

CPU Affinity

In a single core system, the OS allows multiple processes to run by sharing CPU time with the multiple processes. This is called concurrency, which gives the illusion of multiple processes executing at once, but is in fact just using a scheduler to give each process dedicated time on the CPU. The time associated with switching processes on a single core is overhead caused by context switching.

When a multi-core processor is available to an OS (e.g., Linux), the scheduler will do its best to allow processes to run simultaneously (by placing processes on different cores) in addition to running concurrently (different processes on the same core).

To control which core a process runs on, we can tell the scheduler to give a process a certain affinity towards a given set of CPUs.

Using taskset, we can get/set the CPU affinity of a particular process. Consider the following example.

@radiatoryang
radiatoryang / SkinnedMeshCombiner.cs
Last active August 9, 2023 04:12
example code for combining SkinnedMeshRenderers at runtime (for optimization reasons usually), which I use in my games for Mixamo Fuse models specifically... PLEASE DON'T ASK ME FOR HELP WITH THIS, this is more for learning purposes, and it's not really an easy-to-use Asset Store thing? also I have a lot of weird hacks specific for my uses... ag…
// this code is under MIT License, by Robert Yang + others (credits in comments)
// a lot of this is based on http://wiki.unity3d.com/index.php?title=SkinnedMeshCombiner
// but I removed the atlasing stuff because I don't need it
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;