[kernel] Store object ids instead of full koids
In preparation for futexes, I wanted to make kobjects a bit lighter. Storing 32 bits of object id, and 8 bits of type (and not ending the class in a ushort for handle count, which meant all kobjects were likely to have a bunch of pad bytes), the kobject class data is now just one 8 byte word. Also from this, change logs that mention threads or processes from printing the full koid to just 2 bytes of object id from both process and thread, which makes following the logs much easier.
This commit is contained in:
@@ -7,30 +7,29 @@
|
||||
|
||||
namespace obj {
|
||||
|
||||
static j6_koid_t next_koids [static_cast<size_t>(kobject::type::max)] = { 0 };
|
||||
static constexpr unsigned types_count = static_cast<unsigned>(kobject::type::max);
|
||||
|
||||
static uint32_t next_oids [types_count] = { 0 };
|
||||
|
||||
static_assert(types_count <= (1 << kobject::koid_type_bits),
|
||||
"kobject::koid_type_bits cannot represent all kobject types");
|
||||
|
||||
static uint32_t
|
||||
oid_generate(kobject::type t)
|
||||
{
|
||||
kassert(t < kobject::type::max, "Object type out of bounds");
|
||||
unsigned type_int = static_cast<unsigned>(t);
|
||||
return __atomic_fetch_add(&next_oids[type_int], 1, __ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
kobject::kobject(type t) :
|
||||
m_koid(koid_generate(t)),
|
||||
m_handle_count(0)
|
||||
m_handle_count {0},
|
||||
m_type {t},
|
||||
m_obj_id {oid_generate(t)}
|
||||
{}
|
||||
|
||||
kobject::~kobject() {}
|
||||
|
||||
j6_koid_t
|
||||
kobject::koid_generate(type t)
|
||||
{
|
||||
kassert(t < type::max, "Object type out of bounds");
|
||||
uint64_t type_int = static_cast<uint64_t>(t);
|
||||
uint64_t id = __atomic_fetch_add(&next_koids[type_int], 1, __ATOMIC_SEQ_CST);
|
||||
return (type_int << 48) | id;
|
||||
}
|
||||
|
||||
kobject::type
|
||||
kobject::koid_type(j6_koid_t koid)
|
||||
{
|
||||
return static_cast<type>((koid >> 48) & 0xffffull);
|
||||
}
|
||||
|
||||
void
|
||||
kobject::on_no_handles()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user