Messages in this thread | | | Subject | Re: [PATCH 1/5] perf/x86/intel/uncore: Parse uncore discovery tables | From | "Liang, Kan" <> | Date | Tue, 16 Mar 2021 08:29:44 -0400 |
| |
On 3/16/2021 7:40 AM, Peter Zijlstra wrote: > On Fri, Mar 12, 2021 at 08:34:34AM -0800, kan.liang@linux.intel.com wrote: >> +static struct intel_uncore_discovery_type * >> +search_uncore_discovery_type(u16 type_id) >> +{ >> + struct rb_node *node = discovery_tables.rb_node; >> + struct intel_uncore_discovery_type *type; >> + >> + while (node) { >> + type = rb_entry(node, struct intel_uncore_discovery_type, node); >> + >> + if (type->type > type_id) >> + node = node->rb_left; >> + else if (type->type < type_id) >> + node = node->rb_right; >> + else >> + return type; >> + } >> + >> + return NULL; >> +} >> + >> +static struct intel_uncore_discovery_type * >> +add_uncore_discovery_type(struct uncore_unit_discovery *unit) >> +{ >> + struct intel_uncore_discovery_type *type, *cur; >> + struct rb_node **node = &discovery_tables.rb_node; >> + struct rb_node *parent = *node; >> + >> + if (unit->access_type >= UNCORE_ACCESS_MAX) { >> + pr_warn("Unsupported access type %d\n", unit->access_type); >> + return NULL; >> + } >> + >> + type = kzalloc(sizeof(struct intel_uncore_discovery_type), GFP_KERNEL); >> + if (!type) >> + return NULL; >> + >> + type->box_ctrl_die = kcalloc(__uncore_max_dies, sizeof(u64), GFP_KERNEL); >> + if (!type->box_ctrl_die) >> + goto free_type; >> + >> + type->access_type = unit->access_type; >> + num_discovered_types[type->access_type]++; >> + type->type = unit->box_type; >> + >> + while (*node) { >> + parent = *node; >> + cur = rb_entry(parent, struct intel_uncore_discovery_type, node); >> + >> + if (cur->type > type->type) >> + node = &parent->rb_left; >> + else >> + node = &parent->rb_right; >> + } >> + >> + rb_link_node(&type->node, parent, node); >> + rb_insert_color(&type->node, &discovery_tables); >> + >> + return type; >> + >> +free_type: >> + kfree(type); >> + >> + return NULL; >> + >> +} > > I'm thinking this can use some of this: > > 2d24dd5798d0 ("rbtree: Add generic add and find helpers") >
Sure, I will use the generic rbtree framework in V2.
Thanks, Kan
| |