drivers/infiniband/core/counters.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/core/counters.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/core/counters.c- Extension
.c- Size
- 16195 bytes
- Lines
- 690
- Domain
- Driver Families
- Bucket
- drivers/infiniband
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
rdma/ib_verbs.hrdma/rdma_counter.hcore_priv.hrestrack.h
Detected Declarations
function Copyrightfunction rdma_counter_set_auto_modefunction auto_mode_init_counterfunction __rdma_counter_bind_qpfunction rdma_counter_modifyfunction rdma_counter_freefunction auto_mode_matchfunction __rdma_counter_unbind_qpfunction counter_history_stat_updatefunction counter_releasefunction rdma_counter_bind_qp_autofunction rdma_counter_unbind_qpfunction rdma_counter_query_statsfunction get_running_counters_hwstat_sumfunction rdma_counter_get_hwstat_valuefunction rdma_counter_bind_qpnfunction rdma_counter_bind_qpn_allocfunction rdma_counter_unbind_qpnfunction rdma_counter_get_modefunction rdma_counter_initfunction rdma_for_each_portfunction rdma_counter_releasefunction rdma_for_each_port
Annotated Snippet
if (ret) {
mutex_unlock(&port_counter->lock);
goto err_mode;
}
break;
case RDMA_COUNTER_MODE_AUTO:
auto_mode_init_counter(counter, qp, port_counter->mode.mask);
break;
default:
ret = -EOPNOTSUPP;
mutex_unlock(&port_counter->lock);
goto err_mode;
}
port_counter->num_counters++;
mutex_unlock(&port_counter->lock);
counter->mode.mode = mode;
counter->mode.bind_opcnt = bind_opcnt;
kref_init(&counter->kref);
mutex_init(&counter->lock);
ret = __rdma_counter_bind_qp(counter, qp, port);
if (ret)
goto err_bind;
rdma_restrack_parent_name(&counter->res, &qp->res);
rdma_restrack_add(&counter->res);
return counter;
err_bind:
mutex_lock(&port_counter->lock);
port_counter->num_counters--;
if (!port_counter->num_counters &&
port_counter->mode.mode == RDMA_COUNTER_MODE_MANUAL)
__counter_set_mode(port_counter, RDMA_COUNTER_MODE_NONE, 0,
false);
mutex_unlock(&port_counter->lock);
err_mode:
rdma_free_hw_stats_struct(counter->stats);
err_stats:
rdma_restrack_put(&counter->res);
kfree(counter);
return NULL;
}
static void rdma_counter_free(struct rdma_counter *counter)
{
struct rdma_port_counter *port_counter;
port_counter = &counter->device->port_data[counter->port].port_counter;
mutex_lock(&port_counter->lock);
port_counter->num_counters--;
if (!port_counter->num_counters &&
(port_counter->mode.mode == RDMA_COUNTER_MODE_MANUAL))
__counter_set_mode(port_counter, RDMA_COUNTER_MODE_NONE, 0,
false);
mutex_unlock(&port_counter->lock);
rdma_restrack_del(&counter->res);
rdma_free_hw_stats_struct(counter->stats);
kfree(counter);
}
static bool auto_mode_match(struct ib_qp *qp, struct rdma_counter *counter,
enum rdma_nl_counter_mask auto_mask)
{
struct auto_mode_param *param = &counter->mode.param;
bool match = true;
if (auto_mask & RDMA_COUNTER_MASK_QP_TYPE)
match &= (param->qp_type == qp->qp_type);
if (auto_mask & RDMA_COUNTER_MASK_PID)
match &= (task_pid_nr(counter->res.task) ==
task_pid_nr(qp->res.task));
return match;
}
static int __rdma_counter_unbind_qp(struct ib_qp *qp, u32 port)
{
struct rdma_counter *counter = qp->counter;
int ret;
if (!qp->device->ops.counter_unbind_qp)
return -EOPNOTSUPP;
mutex_lock(&counter->lock);
Annotation
- Immediate include surface: `rdma/ib_verbs.h`, `rdma/rdma_counter.h`, `core_priv.h`, `restrack.h`.
- Detected declarations: `function Copyright`, `function rdma_counter_set_auto_mode`, `function auto_mode_init_counter`, `function __rdma_counter_bind_qp`, `function rdma_counter_modify`, `function rdma_counter_free`, `function auto_mode_match`, `function __rdma_counter_unbind_qp`, `function counter_history_stat_update`, `function counter_release`.
- Atlas domain: Driver Families / drivers/infiniband.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.