Heron
Heron

Reputation: 106

How to deal the circumstance of ASIDs are used up in Linux kernel?

ASID(the Address Space Identifier) in ARM architecture occupy 8 bits in a register. That means 256 ASIDs can be allocated. But in linux kernel there are even maor than 1024 tasks can run at the same time. How to deal the circumstance of ASIDs are used up in Linux kernel? I had checked the kernel source code, when the ASIDs are used up, kernel will allocate ASID to new task from start again. Considering one circumstance, the newest task own the first ASID(0b1000 0000 0000 0001), but there is one task must already own the same ASID. What if that two tasks need to cantext switch? I had not found related kernel source code. Related codes in linux kernel is in ~/kernel/core.c context_switch() .Any reply will be appreciated very much, thanks in advance

Best regards. Heron

Upvotes: 4

Views: 1945

Answers (2)

All The Rage
All The Rage

Reputation: 831

There's a great explanation here:

https://community.arm.com/thread/8219

It mostly matches Heron's answer, except that it refers to a bitmap of ASIDs, rather than just incrementing until 255.

Upvotes: 0

Heron
Heron

Reputation: 106

I had found some instructions about that, as follow(Cortex -A9 programmer guide P8-20): ASIDs are dynamically allocated and not guaranteed to be constant during the lifetime of a process. As the ASID register provides only ei ght bits of ASID space and we can have more than 256 processes, Linux has a scheme for allo cating ASIDs. For a new process, we increment the last ASID value used. When the last value is reached, we have to take some action. The TLB is flushed (across all processors in an SMP system). The value in the top 24 bits in the context ID register, which can be considered as a “gener ation” number, is incremented. Stepping to a new generation means that all ASID values from the previous generation are now invalid and ASID numbering is restarted. On a context switch, processes which use an older generation version of the context ID value are assigned a new ASID

So cpu will increment automatically when the ASID is used up, and when context switch kernel will check whether the high-bits are set(old ASID), if so create new ASID for the task. So that can avoid the problem I'd mentioned above.

thanks.

Upvotes: 3

Related Questions