cold and hot attributes in programs?

Discuss any suggestions you may have here.
Post Reply
User avatar
izy
Posts: 25
Joined: Tue Jun 02, 2015 11:34 am

cold and hot attributes in programs?

Post by izy » Mon Feb 01, 2016 2:52 pm

I saw that cen64_cold is applied to all run-once functions with different and unrelated functionalities (such as initialization/finalization functions) and similar functions very rarely used by the program (load/save functions). The reason for the hot/cold attributes to exist is to specify a priority for a function over another inside the same code section. But there is not even a reason for those functions to be placed inside the main section with the core program.
As comparison. Adding a "section" can been seen as the "WHERE" clause in SQL and "hot/cold" like the "ORDER BY" clause. "section" is therefore much more powerful in deciding the final result of what you get.

A simple update for Cen64 would be:

Code: Select all

#define cen64_cold __attribute__((section("icecold"), cold))
#define cen64_hot __attribute__((hot))
The name of a section can be any word you like but it's better if it doesn't start with a dot "." since it could collide with the name of a new section that could be added to the ABI in the future.

Or it's possible to create new complex defines such as:
#define cen64_core /* default code section */
#define cen64_core_cold __attribute__((cold))
#define cen64_core_hot __attribute__((hot))
#define cen64_core_data /* default data section */
#define cen64_util __attribute__((section("util")))
#define cen64_util_cold __attribute__((section("util"), cold))
#define cen64_util_hot __attribute__((section("util"), hot))
#define cen64_util_data __attribute__((section("hello")))
Just important functions can be marked as "cen64_core_hot", all the other functions can be left unmarked and unlikely exceptions for the engine can be marked as "cen64_core_cold". Load/save/initialization functions can be marked as "cen64_util_cold" (though if there is an utility initialization function that is called only one time but is CPU expensive marking it as "cen64_util_hot" would for sure not interfere with the Core program and still would optimize the function for speed). The "section" attribute can be also used to move global variables to different sections (possibly all variables only used by "cen64_util*" functions can get the "cen64_util_data" attribute). Some useful commands to see where the code is placed

Code: Select all

objdump -h cen64   also: readelf -S cen64
objdump -d cen64 -j .text > main-code.txt
objdump -d cen64 -j icecold > icecold-code.txt
objdump -d cen64 -j icecold | grep \>: > cold-functions.txt
readelf -p .rodata cen64 > rd-data.txt

User avatar
MarathonMan
Site Admin
Posts: 692
Joined: Fri Oct 04, 2013 4:49 pm

Re: cold and hot attributes in programs?

Post by MarathonMan » Tue Feb 02, 2016 11:32 pm

I love this! Definitely will look into getting this into the codebase soon.

I can see it being used to possibly keep hot sections of CPU cores in uop cache when there are multiple threads.

But maybe I'm hoping for too much. :D

User avatar
izy
Posts: 25
Joined: Tue Jun 02, 2015 11:34 am

Re: cold and hot attributes in programs?

Post by izy » Mon Feb 08, 2016 12:33 pm

I think that what you're thinking is possible. Btw note that if you get to call a function from a section to another, such as to signal an interrupt to another component, it'll result in a very far function call. This could be avoided forcing inlining or with some code redundancy though. Another way to obtain a similar result is by using shared objects: vr4300.so, rsp.so, what.so, decode.so... Each DLL will have its own code section (with its own hot/cold functions). However since shared objects are relocatable objects with position independent code, a global offset table, the resulting code could be bigger, for example the base-pointer register (rbx/ebx) is used to hold the got addr and is made for the 99.9% unavailable to your code.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest