คุณอาจตรวจสอบลักษณะการทำงานของเธรด CPU ในส่วนการใช้งาน CPU ได้โดยการเปิดใช้ CPU ในการกำหนดค่าโปรไฟล์เมื่อทำการติดตาม การซูมเข้าส่วนหนึ่งของ
การติดตามที่ใช้เวลาน้อยกว่า 200 มิลลิวินาที จะช่วยให้คุณดูแต่ละกระบวนการที่ทำงานในคอร์ CPU ของอุปกรณ์ได้ โดยปกติแล้ว คอร์ขนาดเล็กจะสอดคล้องกับดัชนีขนาดเล็ก (เช่น CPU '0'-'3')
ในขณะที่คอร์ขนาดใหญ่จะสอดคล้องกับดัชนีที่สูงกว่า (เช่น CPU '6'-'7')
และหากมีคอร์ขนาดกลาง คอร์ดังกล่าวจะใช้ดัชนีระหว่างนั้น (เช่น CPU '5'-'6')
ซึ่งเป็นไปตามธรรมเนียมทั่วไป แต่ก็ไม่มีการรับประกันในเรื่องนี้
หากพบว่ามีการกำหนดเวลาให้บางเธรดทำงานใน CPU ที่ไม่ตรงกับความต้องการด้านประสิทธิภาพหรือพลังงาน
ให้พิจารณาตั้งค่าแอฟฟินิตีของ CPU สำหรับเธรดเหล่านั้นด้วยตนเอง
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],null,["# Analyze thread scheduling\n\nThere are a few things to consider in order to determine if your game process threads are appropriately utilized and scheduled for the best performance.\n\n- Frame pacing\n- Multithreading and thread parallelization\n- CPU core affinity\n\nMultithreading\n--------------\n\nMany games and game engines use multithreading to divide CPU work into logical tasks, which may be run somewhat independently. One typical configuration is a game thread for input and game logic, a render thread for preparing and submitting objects to be drawn, and worker threads for other subtasks such as animations or audio.\n\nWe recommend parallelizing threads to take advantage of performance gains of\nmultithreading. An example of this is a scenario where the game and render\nthreads are running partially or fully concurrently on different cores. This\nwon't always be possible, such as in cases with shared data dependencies;\nhowever, when possible, this may result in lower CPU times and thus potentially\nhigher frame rates.\n**Figure 1.**Game with a well-parallelized main and render thread, as well as a worker thread and audio thread\n\nCPU core affinity\n-----------------\n\n| **Important:** CPU core affinity has been superseded by the [Performance Hint API](/games/optimize/adpf/performance-hint-api). Use this API when your app is on a device running Android 12 and later.\n\nOne factor that significantly affects the performance of your CPU workloads is how they are scheduled on the cores. This may be split into two components:\n\n- Whether your game threads are running on the most suitable core for their workload.\n- Whether your game threads switch between cores frequently.\n\nModern devices often use an architecture called *heterogeneous computing*, where the cores have different levels of performance:\n\n- One or a few cores offer top peak performance, but consume more power. These are sometimes called \"big\" cores.\n- Other cores have lower peak performance, but are more power-efficient. These are sometimes called \"little\" cores.\n- Optionally: one or more cores offer a balance between performance and power. These are sometimes called \"mid\" cores.\n\nYou may investigate CPU thread behavior under **CPU Usage** by enabling the\n**CPU** in the profile config when taking a trace. By zooming into a section of\nyour trace \\\u003c200 ms, you can view the individual processes running on your device's CPU cores. Typically, smaller cores correspond to smaller indexes (for example, CPUs '0'-'3')\nwhereas larger cores correspond to higher indexes (for example, CPUs '6'-'7')\nand middle cores if present will occupy indexes in between (for example, CPUs '5'-'6').\nThis is by common convention, but it's not a guarantee.\n\nIf you find that certain threads are being scheduled on CPUs that don't meet their needs for performance or power,\nconsider manually setting the CPU affinity for those threads.\n**Figure 2.**Game with main and render thread primarily running on the large cores (CPU 6-7), shown in light blue\n\nYou may also observe whether your threads switch between cores.\nSuch core switches incur some overhead from the context switch and the loss of state with a core's cache/registers.\n**Figure 3.**Game with main (Thread-7) and render thread (Thread-8) that switch between cores, shown in purple\n\nSetting CPU affinity for a thread instructs the system to schedule it on the given core when your game is in the foreground.\nThere are several factors to consider when doing this:\n\n- The platform software can't dynamically adjust task placement for runtime factors such as load and thermal throttling.\n- Performance testing on different devices may yield very different\n performance characteristics, especially if the devices vary considerably by\n price point or by release date.\n\n A newer or more expensive device might run a given workload comfortably on\n a little core, but an older or more affordable device might require a\n bigger core to meet deadlines for that same workload.\n- By forcing affinities to big cores, you may unnecessarily increase battery\n drain and thermal load.\n\nFor these reasons, it's generally best to avoid manually setting CPU affinities."]]