Skip to content

Commit 5d920b6

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Use __set_bit()/__clear_bit() instead of open coding
The resctrl CLOSID allocator uses a single 32bit word to track which CLOSID are free. The setting and clearing of bits is open coded. Convert the existing open coded bit manipulations of closid_free_map to use __set_bit() and friends. These don't need to be atomic as this list is protected by the mutex. Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Reviewed-by: Babu Moger <babu.moger@amd.com> Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Babu Moger <babu.moger@amd.com> Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64 Link: https://lore.kernel.org/r/20240213184438.16675-10-james.morse@arm.com Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
1 parent b30a55d commit 5d920b6

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

arch/x86/kernel/cpu/resctrl/rdtgroup.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void rdt_staged_configs_clear(void)
111111
* - Our choices on how to configure each resource become progressively more
112112
* limited as the number of resources grows.
113113
*/
114-
static int closid_free_map;
114+
static unsigned long closid_free_map;
115115
static int closid_free_map_len;
116116

117117
int closids_supported(void)
@@ -130,26 +130,30 @@ static void closid_init(void)
130130

131131
closid_free_map = BIT_MASK(rdt_min_closid) - 1;
132132

133-
/* CLOSID 0 is always reserved for the default group */
134-
closid_free_map &= ~1;
133+
/* RESCTRL_RESERVED_CLOSID is always reserved for the default group */
134+
__clear_bit(RESCTRL_RESERVED_CLOSID, &closid_free_map);
135135
closid_free_map_len = rdt_min_closid;
136136
}
137137

138138
static int closid_alloc(void)
139139
{
140140
u32 closid = ffs(closid_free_map);
141141

142+
lockdep_assert_held(&rdtgroup_mutex);
143+
142144
if (closid == 0)
143145
return -ENOSPC;
144146
closid--;
145-
closid_free_map &= ~(1 << closid);
147+
__clear_bit(closid, &closid_free_map);
146148

147149
return closid;
148150
}
149151

150152
void closid_free(int closid)
151153
{
152-
closid_free_map |= 1 << closid;
154+
lockdep_assert_held(&rdtgroup_mutex);
155+
156+
__set_bit(closid, &closid_free_map);
153157
}
154158

155159
/**
@@ -161,7 +165,9 @@ void closid_free(int closid)
161165
*/
162166
static bool closid_allocated(unsigned int closid)
163167
{
164-
return (closid_free_map & (1 << closid)) == 0;
168+
lockdep_assert_held(&rdtgroup_mutex);
169+
170+
return !test_bit(closid, &closid_free_map);
165171
}
166172

167173
/**

0 commit comments

Comments
 (0)