Skip to content

Commit a2e28b5

Browse files
committed
components: allocate the backend private_data together with the backend structure
This breaks the component ABI, but it was already bumped from 7 to 8 in bf44f30. Signed-off-by: Brice Goglin <[email protected]>
1 parent d064884 commit a2e28b5

22 files changed

+79
-107
lines changed

hwloc/components.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2009-2022 Inria. All rights reserved.
2+
* Copyright © 2009-2023 Inria. All rights reserved.
33
* Copyright © 2012 Université Bordeaux
44
* See COPYING in top-level directory.
55
*/
@@ -930,9 +930,10 @@ hwloc_components_fini(void)
930930

931931
struct hwloc_backend *
932932
hwloc_backend_alloc(struct hwloc_topology *topology,
933-
struct hwloc_disc_component *component)
933+
struct hwloc_disc_component *component,
934+
unsigned long private_data_size)
934935
{
935-
struct hwloc_backend * backend = malloc(sizeof(*backend));
936+
struct hwloc_backend * backend = malloc(sizeof(*backend) + private_data_size);
936937
if (!backend) {
937938
errno = ENOMEM;
938939
return NULL;

hwloc/topology-aix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2009 CNRS
3-
* Copyright © 2009-2022 Inria. All rights reserved.
3+
* Copyright © 2009-2023 Inria. All rights reserved.
44
* Copyright © 2009-2011, 2013 Université Bordeaux
55
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
66
* See COPYING in top-level directory.
@@ -878,7 +878,7 @@ hwloc_aix_component_instantiate(struct hwloc_topology *topology,
878878
const void *_data3 __hwloc_attribute_unused)
879879
{
880880
struct hwloc_backend *backend;
881-
backend = hwloc_backend_alloc(topology, component);
881+
backend = hwloc_backend_alloc(topology, component, 0);
882882
if (!backend)
883883
return NULL;
884884
backend->discover = hwloc_look_aix;

hwloc/topology-cuda.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2011 Université Bordeaux
3-
* Copyright © 2012-2022 Inria. All rights reserved.
3+
* Copyright © 2012-2023 Inria. All rights reserved.
44
* See COPYING in top-level directory.
55
*/
66

@@ -153,7 +153,7 @@ hwloc_cuda_component_instantiate(struct hwloc_topology *topology,
153153
{
154154
struct hwloc_backend *backend;
155155

156-
backend = hwloc_backend_alloc(topology, component);
156+
backend = hwloc_backend_alloc(topology, component, 0);
157157
if (!backend)
158158
return NULL;
159159
/* the first callback will initialize those */

hwloc/topology-darwin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ hwloc_darwin_component_instantiate(struct hwloc_topology *topology,
920920
const void *_data3 __hwloc_attribute_unused)
921921
{
922922
struct hwloc_backend *backend;
923-
backend = hwloc_backend_alloc(topology, component);
923+
backend = hwloc_backend_alloc(topology, component, 0);
924924
if (!backend)
925925
return NULL;
926926
backend->discover = hwloc_look_darwin;

hwloc/topology-fake.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2012-2019 Inria. All rights reserved.
2+
* Copyright © 2012-2023 Inria. All rights reserved.
33
* See COPYING in top-level directory.
44
*/
55

@@ -44,7 +44,7 @@ hwloc_fake_component_instantiate(struct hwloc_topology *topology __hwloc_attribu
4444
{
4545
struct hwloc_backend *backend;
4646

47-
backend = hwloc_backend_alloc(topology, component);
47+
backend = hwloc_backend_alloc(topology, component, 0);
4848
if (!backend)
4949
goto out;
5050
backend->discover = hwloc_look_fake;

hwloc/topology-freebsd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2009 CNRS
3-
* Copyright © 2009-2022 Inria. All rights reserved.
3+
* Copyright © 2009-2023 Inria. All rights reserved.
44
* Copyright © 2009-2010, 2012, 2020 Université Bordeaux
55
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
66
* See COPYING in top-level directory.
@@ -595,7 +595,7 @@ hwloc_freebsd_component_instantiate(struct hwloc_topology *topology,
595595
const void *_data3 __hwloc_attribute_unused)
596596
{
597597
struct hwloc_backend *backend;
598-
backend = hwloc_backend_alloc(topology, component);
598+
backend = hwloc_backend_alloc(topology, component, 0);
599599
if (!backend)
600600
return NULL;
601601
backend->discover = hwloc_look_freebsd;

hwloc/topology-gl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2012-2013 Blue Brain Project, BBP/EPFL. All rights reserved.
3-
* Copyright © 2012-2021 Inria. All rights reserved.
3+
* Copyright © 2012-2023 Inria. All rights reserved.
44
* See COPYING in top-level directory.
55
*/
66

@@ -154,7 +154,7 @@ hwloc_gl_component_instantiate(struct hwloc_topology *topology,
154154
{
155155
struct hwloc_backend *backend;
156156

157-
backend = hwloc_backend_alloc(topology, component);
157+
backend = hwloc_backend_alloc(topology, component, 0);
158158
if (!backend)
159159
return NULL;
160160
backend->discover = hwloc_gl_discover;

hwloc/topology-hpux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2009 CNRS
3-
* Copyright © 2009-2020 Inria. All rights reserved.
3+
* Copyright © 2009-2023 Inria. All rights reserved.
44
* Copyright © 2009-2010, 2013 Université Bordeaux
55
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
66
* See COPYING in top-level directory.
@@ -307,7 +307,7 @@ hwloc_hpux_component_instantiate(struct hwloc_topology *topology,
307307
const void *_data3 __hwloc_attribute_unused)
308308
{
309309
struct hwloc_backend *backend;
310-
backend = hwloc_backend_alloc(topology, component);
310+
backend = hwloc_backend_alloc(topology, component, 0);
311311
if (!backend)
312312
return NULL;
313313
backend->discover = hwloc_look_hpux;

hwloc/topology-levelzero.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ hwloc_levelzero_component_instantiate(struct hwloc_topology *topology,
839839
{
840840
struct hwloc_backend *backend;
841841

842-
backend = hwloc_backend_alloc(topology, component);
842+
backend = hwloc_backend_alloc(topology, component, 0);
843843
if (!backend)
844844
return NULL;
845845
backend->discover = hwloc_levelzero_discover;

hwloc/topology-linux.c

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5571,7 +5571,7 @@ static int
55715571
hwloc_linux_try_hardwired_cpuinfo(struct hwloc_backend *backend)
55725572
{
55735573
struct hwloc_topology *topology = backend->topology;
5574-
struct hwloc_linux_backend_data_s *data = backend->private_data;
5574+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
55755575

55765576
if (getenv("HWLOC_NO_HARDWIRED_TOPOLOGY"))
55775577
return -1;
@@ -5625,7 +5625,7 @@ static void
56255625
hwloc_linux_fallback_pu_level(struct hwloc_backend *backend)
56265626
{
56275627
struct hwloc_topology *topology = backend->topology;
5628-
struct hwloc_linux_backend_data_s *data = backend->private_data;
5628+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
56295629

56305630
if (data->fallback_nbprocessors >= 1)
56315631
topology->support.discovery->pu = 1;
@@ -5730,7 +5730,7 @@ hwloc_linuxfs_look_cpu(struct hwloc_backend *backend, struct hwloc_disc_status *
57305730
*/
57315731

57325732
struct hwloc_topology *topology = backend->topology;
5733-
struct hwloc_linux_backend_data_s *data = backend->private_data;
5733+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
57345734
unsigned nbnodes;
57355735
char *cpuset_name = NULL;
57365736
struct hwloc_linux_cpuinfo_proc * Lprocs = NULL;
@@ -5895,7 +5895,7 @@ static int
58955895
hwloc_linux_backend_get_pci_busid_cpuset(struct hwloc_backend *backend,
58965896
struct hwloc_pcidev_attr_s *busid, hwloc_bitmap_t cpuset)
58975897
{
5898-
struct hwloc_linux_backend_data_s *data = backend->private_data;
5898+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
58995899
char path[256];
59005900
int err;
59015901

@@ -6068,7 +6068,7 @@ hwloc_linuxfs_block_class_fillinfos(struct hwloc_backend *backend __hwloc_attrib
60686068
struct hwloc_obj *obj, const char *osdevpath)
60696069
{
60706070
#ifdef HWLOC_HAVE_LIBUDEV
6071-
struct hwloc_linux_backend_data_s *data = backend->private_data;
6071+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
60726072
#endif
60736073
FILE *file;
60746074
char path[296]; /* osdevpath <= 256 */
@@ -6238,7 +6238,7 @@ hwloc_linuxfs_block_class_fillinfos(struct hwloc_backend *backend __hwloc_attrib
62386238
static int
62396239
hwloc_linuxfs_lookup_block_class(struct hwloc_backend *backend, unsigned osdev_flags)
62406240
{
6241-
struct hwloc_linux_backend_data_s *data = backend->private_data;
6241+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
62426242
int root_fd = data->root_fd;
62436243
DIR *dir;
62446244
struct dirent *dirent;
@@ -6319,7 +6319,7 @@ hwloc_linuxfs_dax_class_fillinfos(struct hwloc_backend *backend __hwloc_attribut
63196319
static int
63206320
hwloc_linuxfs_lookup_dax_class(struct hwloc_backend *backend, unsigned osdev_flags)
63216321
{
6322-
struct hwloc_linux_backend_data_s *data = backend->private_data;
6322+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
63236323
int root_fd = data->root_fd;
63246324
DIR *dir;
63256325
struct dirent *dirent;
@@ -6407,7 +6407,7 @@ hwloc_linuxfs_net_class_fillinfos(int root_fd,
64076407
static int
64086408
hwloc_linuxfs_lookup_net_class(struct hwloc_backend *backend, unsigned osdev_flags)
64096409
{
6410-
struct hwloc_linux_backend_data_s *data = backend->private_data;
6410+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
64116411
int root_fd = data->root_fd;
64126412
DIR *dir;
64136413
struct dirent *dirent;
@@ -6524,7 +6524,7 @@ hwloc_linuxfs_infiniband_class_fillinfos(int root_fd,
65246524
static int
65256525
hwloc_linuxfs_lookup_infiniband_class(struct hwloc_backend *backend, unsigned osdev_flags)
65266526
{
6527-
struct hwloc_linux_backend_data_s *data = backend->private_data;
6527+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
65286528
int root_fd = data->root_fd;
65296529
DIR *dir;
65306530
struct dirent *dirent;
@@ -6582,7 +6582,7 @@ hwloc_linuxfs_bxi_class_fillinfos(int root_fd,
65826582
static int
65836583
hwloc_linuxfs_lookup_bxi_class(struct hwloc_backend *backend, unsigned osdev_flags)
65846584
{
6585-
struct hwloc_linux_backend_data_s *data = backend->private_data;
6585+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
65866586
int root_fd = data->root_fd;
65876587
DIR *dir;
65886588
struct dirent *dirent;
@@ -6693,7 +6693,7 @@ hwloc_linuxfs_ve_class_fillinfos(int root_fd,
66936693
static int
66946694
hwloc_linuxfs_lookup_ve_class(struct hwloc_backend *backend, unsigned osdev_flags)
66956695
{
6696-
struct hwloc_linux_backend_data_s *data = backend->private_data;
6696+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
66976697
int root_fd = data->root_fd;
66986698
DIR *dir;
66996699
struct dirent *dirent;
@@ -6730,7 +6730,7 @@ hwloc_linuxfs_lookup_ve_class(struct hwloc_backend *backend, unsigned osdev_flag
67306730
static int
67316731
hwloc_linuxfs_lookup_drm_class(struct hwloc_backend *backend, unsigned osdev_flags)
67326732
{
6733-
struct hwloc_linux_backend_data_s *data = backend->private_data;
6733+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
67346734
int root_fd = data->root_fd;
67356735
DIR *dir;
67366736
struct dirent *dirent;
@@ -6785,7 +6785,7 @@ hwloc_linuxfs_lookup_drm_class(struct hwloc_backend *backend, unsigned osdev_fla
67856785
static int
67866786
hwloc_linuxfs_lookup_dma_class(struct hwloc_backend *backend, unsigned osdev_flags)
67876787
{
6788-
struct hwloc_linux_backend_data_s *data = backend->private_data;
6788+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
67896789
int root_fd = data->root_fd;
67906790
DIR *dir;
67916791
struct dirent *dirent;
@@ -6846,7 +6846,7 @@ hwloc_linuxfs_cxlmem_fillinfos(int root_fd,
68466846
static int
68476847
hwloc_linuxfs_lookup_cxlmem(struct hwloc_backend *backend, unsigned osdev_flags)
68486848
{
6849-
struct hwloc_linux_backend_data_s *data = backend->private_data;
6849+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
68506850
int root_fd = data->root_fd;
68516851
DIR *dir;
68526852
struct dirent *dirent;
@@ -7066,7 +7066,7 @@ hwloc__get_firmware_dmi_memory_info(struct hwloc_topology *topology,
70667066
static int
70677067
hwloc_linuxfs_pci_look_pcidevices(struct hwloc_backend *backend)
70687068
{
7069-
struct hwloc_linux_backend_data_s *data = backend->private_data;
7069+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
70707070
struct hwloc_topology *topology = backend->topology;
70717071
hwloc_obj_t tree = NULL;
70727072
int root_fd = data->root_fd;
@@ -7234,7 +7234,7 @@ static int
72347234
hwloc_linuxfs_pci_look_pcislots(struct hwloc_backend *backend)
72357235
{
72367236
struct hwloc_topology *topology = backend->topology;
7237-
struct hwloc_linux_backend_data_s *data = backend->private_data;
7237+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
72387238
int root_fd = data->root_fd;
72397239
DIR *dir;
72407240
struct dirent *dirent;
@@ -7349,7 +7349,7 @@ hwloc_look_linuxfs(struct hwloc_backend *backend, struct hwloc_disc_status *dsta
73497349

73507350
if (dstatus->phase == HWLOC_DISC_PHASE_MISC
73517351
&& mfilter != HWLOC_TYPE_FILTER_KEEP_NONE) {
7352-
hwloc__get_firmware_dmi_memory_info(topology, backend->private_data);
7352+
hwloc__get_firmware_dmi_memory_info(topology, HWLOC_BACKEND_PRIVATE_DATA(backend));
73537353
}
73547354
#endif /* HWLOC_HAVE_LINUXIO */
73557355

@@ -7363,7 +7363,7 @@ hwloc_look_linuxfs(struct hwloc_backend *backend, struct hwloc_disc_status *dsta
73637363
static void
73647364
hwloc_linux_backend_disable(struct hwloc_backend *backend)
73657365
{
7366-
struct hwloc_linux_backend_data_s *data = backend->private_data;
7366+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
73677367
#ifdef HAVE_OPENAT
73687368
if (data->root_fd >= 0) {
73697369
free(data->root_path);
@@ -7374,7 +7374,6 @@ hwloc_linux_backend_disable(struct hwloc_backend *backend)
73747374
if (data->udev)
73757375
udev_unref(data->udev);
73767376
#endif
7377-
free(data);
73787377
}
73797378

73807379
static struct hwloc_backend *
@@ -7391,17 +7390,12 @@ hwloc_linux_component_instantiate(struct hwloc_topology *topology,
73917390
int root = -1;
73927391
char *env;
73937392

7394-
backend = hwloc_backend_alloc(topology, component);
7393+
backend = hwloc_backend_alloc(topology, component, sizeof(struct hwloc_linux_backend_data_s));
73957394
if (!backend)
73967395
goto out;
73977396

7398-
data = malloc(sizeof(*data));
7399-
if (!data) {
7400-
errno = ENOMEM;
7401-
goto out_with_backend;
7402-
}
7397+
data = HWLOC_BACKEND_PRIVATE_DATA(backend);
74037398

7404-
backend->private_data = data;
74057399
backend->discover = hwloc_look_linuxfs;
74067400
backend->get_pci_busid_cpuset = hwloc_linux_backend_get_pci_busid_cpuset;
74077401
backend->disable = hwloc_linux_backend_disable;
@@ -7476,8 +7470,6 @@ hwloc_linux_component_instantiate(struct hwloc_topology *topology,
74767470
#ifdef HAVE_OPENAT
74777471
free(data->root_path);
74787472
#endif
7479-
free(data);
7480-
out_with_backend:
74817473
free(backend);
74827474
out:
74837475
return NULL;

0 commit comments

Comments
 (0)