• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #853

19 Dec 2022 01:01AM UTC coverage: 86.287% (+0.4%) from 85.912%
#853

push

StellarBot
Merge #6109

6109: Modernize serialization module r=hkaiser a=hkaiser

- flyby separate serialization of Boost types

working towards https://github.com/STEllAR-GROUP/hpx/issues/5497

Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

53 of 53 new or added lines in 6 files covered. (100.0%)

173939 of 201582 relevant lines covered (86.29%)

1931657.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

47.11
/libs/full/agas_base/src/server/locality_namespace_server.cpp
1
//  Copyright (c) 2011 Bryce Adelstein-Lelbach
2
//  Copyright (c) 2012-2021 Hartmut Kaiser
3
//  Copyright (c) 2016 Thomas Heller
4
//
5
//  SPDX-License-Identifier: BSL-1.0
6
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
7
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8

9
#include <hpx/config.hpp>
10
#include <hpx/agas_base/server/locality_namespace.hpp>
11
#include <hpx/agas_base/server/primary_namespace.hpp>
12
#include <hpx/assert.hpp>
13
#include <hpx/async_distributed/continuation.hpp>
14
#include <hpx/components_base/component_type.hpp>
15
#include <hpx/modules/format.hpp>
16
#include <hpx/modules/logging.hpp>
17
#include <hpx/naming/credit_handling.hpp>
18
#include <hpx/serialization/vector.hpp>
19
#include <hpx/timing/scoped_timer.hpp>
20
#include <hpx/util/get_and_reset_value.hpp>
21
#include <hpx/util/insert_checked.hpp>
22

23
#include <atomic>
24
#include <cstddef>
25
#include <cstdint>
26
#include <list>
27
#include <map>
28
#include <mutex>
29
#include <string>
30
#include <utility>
31
#include <vector>
32

33
namespace hpx { namespace agas {
34

35
    naming::gid_type bootstrap_locality_namespace_gid()
×
36
    {
37
        return naming::gid_type(agas::primary_ns_msb, agas::locality_ns_lsb);
×
38
    }
39

40
    hpx::id_type bootstrap_locality_namespace_id()
×
41
    {
42
        return hpx::id_type(agas::locality_ns_msb, agas::locality_ns_lsb,
×
43
            hpx::id_type::management_type::unmanaged);
44
    }
45
}}    // namespace hpx::agas
46

47
namespace hpx { namespace agas { namespace server {
48

49
    void locality_namespace::register_server_instance(
451✔
50
        char const* servicename, error_code& ec)
51
    {
52
        // now register this AGAS instance with AGAS :-P
53
        instance_name_ = agas::service_name;
451✔
54
        instance_name_ += servicename;
451✔
55
        instance_name_ += agas::server::locality_namespace_service_name;
451✔
56

57
        // register a gid (not the id) to avoid AGAS holding a reference to this
58
        // component
59
        agas::register_name(
451✔
60
            launch::sync, instance_name_, get_unmanaged_id().get_gid(), ec);
451✔
61
    }
451✔
62

63
    void locality_namespace::unregister_server_instance(error_code& ec)
×
64
    {
65
        agas::unregister_name(launch::sync, instance_name_, ec);
×
66
        this->base_type::finalize();
×
67
    }
×
68

69
    void locality_namespace::finalize()
×
70
    {
71
        if (!instance_name_.empty())
×
72
        {
73
            error_code ec(throwmode::lightweight);
×
74
            agas::unregister_name(launch::sync, instance_name_, ec);
×
75
        }
×
76
    }
×
77

78
    std::uint32_t locality_namespace::allocate(
592✔
79
        parcelset::endpoints_type const& endpoints, std::uint64_t count,
80
        std::uint32_t num_threads, naming::gid_type suggested_prefix)
81
    {    // {{{ allocate implementation
82
        util::scoped_timer<std::atomic<std::int64_t>> update(
592✔
83
            counter_data_.allocate_.time_, counter_data_.allocate_.enabled_);
592✔
84
        counter_data_.increment_allocate_count();
592✔
85

86
        using hpx::get;
87

88
        std::unique_lock<mutex_type> l(mutex_);
592✔
89

90
#if defined(HPX_DEBUG)
91
        for (partition_table_type::value_type const& partition : partitions_)
734✔
92
        {
93
            HPX_ASSERT(get<0>(partition.second) != endpoints);
142✔
94
        }
95
#endif
96
        // Check for address space exhaustion.
97
        if (HPX_UNLIKELY(0xFFFFFFFE < partitions_.size()))    //-V104
592✔
98
        {
99
            l.unlock();
×
100

101
            HPX_THROW_EXCEPTION(hpx::error::internal_server_error,
×
102
                "locality_namespace::allocate",
103
                "primary namespace has been exhausted");
104
        }
105

106
        // Compute the locality's prefix.
107
        std::uint32_t prefix = naming::invalid_locality_id;
592✔
108

109
        // check if the suggested prefix can be used instead of the next
110
        // free one
111
        std::uint32_t suggested_locality_id =
592✔
112
            naming::get_locality_id_from_gid(suggested_prefix);
592✔
113

114
        partition_table_type::iterator it = partitions_.end();
592✔
115
        if (suggested_locality_id != naming::invalid_locality_id)
592✔
116
        {
117
            it = partitions_.find(suggested_locality_id);
140✔
118

119
            if (it == partitions_.end())
140✔
120
            {
121
                prefix = suggested_locality_id;
140✔
122
            }
140✔
123
            else
124
            {
125
                do
×
126
                {
127
                    prefix = prefix_counter_++;
×
128
                    it = partitions_.find(prefix);
×
129
                } while (it != partitions_.end());
×
130
            }
131
        }
140✔
132
        else
133
        {
134
            do
452✔
135
            {
136
                prefix = prefix_counter_++;
452✔
137
                it = partitions_.find(prefix);
452✔
138
            } while (it != partitions_.end());
452✔
139
        }
140

141
        // We need to create an entry in the partition table for this
142
        // locality.
143
        if (HPX_UNLIKELY(!util::insert_checked(
592✔
144
                partitions_.insert(std::make_pair(
145
                    prefix, partition_type(endpoints, num_threads))),
146
                it)))
147
        {
148
            l.unlock();
×
149

150
            HPX_THROW_EXCEPTION(hpx::error::lock_error,
×
151
                "locality_namespace::allocate",
152
                "partition table insertion failed due to a locking "
153
                "error or memory corruption, endpoint({1}), "
154
                "prefix({2})",
155
                endpoints, prefix);
156
        }
157

158
        // Now that we've inserted the locality into the partition table
159
        // successfully, we need to put the locality's GID into the GVA
160
        // table so that parcels can be sent to the memory of a locality.
161
        if (primary_)
592✔
162
        {
163
            naming::gid_type id(naming::get_gid_from_locality_id(prefix));
592✔
164
            gva const g(id, components::component_runtime_support, count);
592✔
165

166
            if (!primary_->bind_gid(g, id, id))
592✔
167
            {
168
                HPX_THROW_EXCEPTION(hpx::error::bad_request,
×
169
                    "locality_namespace::allocate",
170
                    "unable to bind prefix({1}) to a gid", prefix);
171
            }
172
            return prefix;
592✔
173
        }
174

175
        LAGAS_(info).format(
×
176
            "locality_namespace::allocate, ep({1}), count({2}), prefix({3})",
×
177
            endpoints, count, prefix);
×
178

179
        return prefix;
×
180
    }    // }}}
592✔
181

182
    parcelset::endpoints_type locality_namespace::resolve_locality(
×
183
        naming::gid_type const& locality)
184
    {    // {{{ resolve_locality implementation
185
        util::scoped_timer<std::atomic<std::int64_t>> update(
×
186
            counter_data_.resolve_locality_.time_,
×
187
            counter_data_.resolve_locality_.enabled_);
×
188
        counter_data_.increment_resolve_locality_count();
×
189

190
        using hpx::get;
191
        std::uint32_t prefix = naming::get_locality_id_from_gid(locality);
×
192

193
        std::lock_guard<mutex_type> l(mutex_);
×
194
        partition_table_type::iterator it = partitions_.find(prefix);
×
195

196
        if (it != partitions_.end())
×
197
        {
198
            return get<0>(it->second);
×
199
        }
200

201
        return parcelset::endpoints_type();
×
202
    }    // }}}
×
203

204
    void locality_namespace::free(naming::gid_type const& locality)
592✔
205
    {    // {{{ free implementation
206
        util::scoped_timer<std::atomic<std::int64_t>> update(
592✔
207
            counter_data_.free_.time_, counter_data_.free_.enabled_);
592✔
208
        counter_data_.increment_free_count();
592✔
209

210
        using hpx::get;
211

212
        // parameters
213
        std::uint32_t prefix = naming::get_locality_id_from_gid(locality);
592✔
214

215
        std::unique_lock<mutex_type> l(mutex_);
592✔
216

217
        partition_table_type::iterator pit = partitions_.find(prefix),
592✔
218
                                       pend = partitions_.end();
592✔
219

220
        if (pit != pend)
592✔
221
        {
222
            /*
223
        // Wipe the locality from the tables.
224
        naming::gid_type locality =
225
            naming::get_gid_from_locality_id(get<0>(pit->second));
226

227
        // first remove entry from reverse partition table
228
        prefixes_.erase(get<0>(pit->second));
229
        */
230

231
            // now remove it from the main partition table
232
            partitions_.erase(pit);
592✔
233

234
            if (primary_)
592✔
235
            {
236
                l.unlock();
592✔
237

238
                // remove primary namespace
239
                {
240
                    naming::gid_type service(
592✔
241
                        agas::primary_ns_msb, agas::primary_ns_lsb);
242
                    primary_->unbind_gid(
1,184✔
243
                        1, naming::replace_locality_id(service, prefix));
592✔
244
                }
245

246
                // remove symbol namespace
247
                {
248
                    naming::gid_type service(
592✔
249
                        agas::symbol_ns_msb, agas::symbol_ns_lsb);
250
                    primary_->unbind_gid(
1,184✔
251
                        1, naming::replace_locality_id(service, prefix));
592✔
252
                }
253

254
                // remove locality itself
255
                {
256
                    primary_->unbind_gid(0, locality);
592✔
257
                }
258
            }
592✔
259

260
            /*LAGAS_(info).format("locality_namespace::free, ep({1})", ep);*/
261
        }
592✔
262

263
        /*LAGAS_(info).format(
264
            "locality_namespace::free, ep({1}), response(no_success)", ep);*/
265
    }    // }}}
592✔
266

267
    std::vector<std::uint32_t> locality_namespace::localities()
1,439✔
268
    {    // {{{ localities implementation
269
        util::scoped_timer<std::atomic<std::int64_t>> update(
1,439✔
270
            counter_data_.localities_.time_,
1,439✔
271
            counter_data_.localities_.enabled_);
1,439✔
272
        counter_data_.increment_localities_count();
1,439✔
273

274
        std::lock_guard<mutex_type> l(mutex_);
1,439✔
275

276
        std::vector<std::uint32_t> p;
1,439✔
277

278
        partition_table_type::const_iterator it = partitions_.begin(),
1,439✔
279
                                             end = partitions_.end();
1,439✔
280

281
        for (/**/; it != end; ++it)
3,346✔
282
            p.push_back(it->first);
1,907✔
283

284
        LAGAS_(info).format(
1,439✔
285
            "locality_namespace::localities, localities({1})", p.size());
×
286

287
        return p;
1,439✔
288
    }    // }}}
1,439✔
289

290
    std::uint32_t locality_namespace::get_num_localities()
376✔
291
    {    // {{{ get_num_localities implementation
292
        util::scoped_timer<std::atomic<std::int64_t>> update(
376✔
293
            counter_data_.num_localities_.time_,
376✔
294
            counter_data_.num_localities_.enabled_);
376✔
295
        counter_data_.increment_num_localities_count();
376✔
296
        std::lock_guard<mutex_type> l(mutex_);
376✔
297

298
        std::uint32_t num_localities =
376✔
299
            static_cast<std::uint32_t>(partitions_.size());
376✔
300

301
        LAGAS_(info).format(
376✔
302
            "locality_namespace::get_num_localities, localities({1})",
×
303
            num_localities);
304

305
        return num_localities;
376✔
306
    }    // }}}
376✔
307

308
    std::vector<std::uint32_t> locality_namespace::get_num_threads()
×
309
    {    // {{{ get_num_threads implementation
310
        std::lock_guard<mutex_type> l(mutex_);
×
311

312
        std::vector<std::uint32_t> num_threads;
×
313

314
        partition_table_type::iterator end = partitions_.end();
×
315
        for (partition_table_type::iterator it = partitions_.begin(); it != end;
×
316
             ++it)
×
317
        {
318
            using hpx::get;
319
            num_threads.push_back(get<1>(it->second));
×
320
        }
×
321

322
        LAGAS_(info).format(
×
323
            "locality_namespace::get_num_threads, localities({1})",
×
324
            num_threads.size());
×
325

326
        return num_threads;
×
327
    }    // }}}
×
328

329
    std::uint32_t locality_namespace::get_num_overall_threads()
11✔
330
    {
331
        std::lock_guard<mutex_type> l(mutex_);
11✔
332

333
        std::uint32_t num_threads = 0;
11✔
334

335
        partition_table_type::iterator end = partitions_.end();
11✔
336
        for (partition_table_type::iterator it = partitions_.begin(); it != end;
22✔
337
             ++it)
11✔
338
        {
339
            using hpx::get;
340
            num_threads += get<1>(it->second);
11✔
341
        }
11✔
342

343
        LAGAS_(info).format(
11✔
344
            "locality_namespace::get_num_overall_threads, localities({1})",
×
345
            num_threads);
346

347
        return num_threads;
11✔
348
    }
11✔
349

350
    // access current counter values
351
    std::int64_t locality_namespace::counter_data::get_allocate_count(
×
352
        bool reset)
353
    {
354
        return util::get_and_reset_value(allocate_.count_, reset);
×
355
    }
356

357
    std::int64_t locality_namespace::counter_data::get_resolve_locality_count(
×
358
        bool reset)
359
    {
360
        return util::get_and_reset_value(resolve_locality_.count_, reset);
×
361
    }
362

363
    std::int64_t locality_namespace::counter_data::get_free_count(bool reset)
×
364
    {
365
        return util::get_and_reset_value(free_.count_, reset);
×
366
    }
367

368
    std::int64_t locality_namespace::counter_data::get_localities_count(
×
369
        bool reset)
370
    {
371
        return util::get_and_reset_value(localities_.count_, reset);
×
372
    }
373

374
    std::int64_t locality_namespace::counter_data::get_num_localities_count(
×
375
        bool reset)
376
    {
377
        return util::get_and_reset_value(num_localities_.count_, reset);
×
378
    }
379

380
    std::int64_t locality_namespace::counter_data::get_num_threads_count(
×
381
        bool reset)
382
    {
383
        return util::get_and_reset_value(num_threads_.count_, reset);
×
384
    }
385

386
    std::int64_t locality_namespace::counter_data::get_overall_count(bool reset)
×
387
    {
388
        return util::get_and_reset_value(allocate_.count_, reset) +
×
389
            util::get_and_reset_value(resolve_locality_.count_, reset) +
×
390
            util::get_and_reset_value(free_.count_, reset) +
×
391
            util::get_and_reset_value(localities_.count_, reset) +
×
392
            util::get_and_reset_value(num_localities_.count_, reset) +
×
393
            util::get_and_reset_value(num_threads_.count_, reset);
×
394
    }
395

396
    void locality_namespace::counter_data::enable_all()
×
397
    {
398
        allocate_.enabled_ = true;
×
399
        resolve_locality_.enabled_ = true;
×
400
        free_.enabled_ = true;
×
401
        localities_.enabled_ = true;
×
402
        num_localities_.enabled_ = true;
×
403
        num_threads_.enabled_ = true;
×
404
    }
×
405

406
    // access execution time counters
407
    std::int64_t locality_namespace::counter_data::get_allocate_time(bool reset)
×
408
    {
409
        return util::get_and_reset_value(allocate_.time_, reset);
×
410
    }
411

412
    std::int64_t locality_namespace::counter_data::get_resolve_locality_time(
×
413
        bool reset)
414
    {
415
        return util::get_and_reset_value(resolve_locality_.time_, reset);
×
416
    }
417

418
    std::int64_t locality_namespace::counter_data::get_free_time(bool reset)
×
419
    {
420
        return util::get_and_reset_value(free_.time_, reset);
×
421
    }
422

423
    std::int64_t locality_namespace::counter_data::get_localities_time(
×
424
        bool reset)
425
    {
426
        return util::get_and_reset_value(localities_.time_, reset);
×
427
    }
428

429
    std::int64_t locality_namespace::counter_data::get_num_localities_time(
×
430
        bool reset)
431
    {
432
        return util::get_and_reset_value(num_localities_.time_, reset);
×
433
    }
434

435
    std::int64_t locality_namespace::counter_data::get_num_threads_time(
×
436
        bool reset)
437
    {
438
        return util::get_and_reset_value(num_threads_.time_, reset);
×
439
    }
440

441
    std::int64_t locality_namespace::counter_data::get_overall_time(bool reset)
×
442
    {
443
        return util::get_and_reset_value(allocate_.time_, reset) +
×
444
            util::get_and_reset_value(resolve_locality_.time_, reset) +
×
445
            util::get_and_reset_value(free_.time_, reset) +
×
446
            util::get_and_reset_value(localities_.time_, reset) +
×
447
            util::get_and_reset_value(num_localities_.time_, reset) +
×
448
            util::get_and_reset_value(num_threads_.time_, reset);
×
449
    }
450

451
    // increment counter values
452
    void locality_namespace::counter_data::increment_allocate_count()
592✔
453
    {
454
        if (allocate_.enabled_)
592✔
455
        {
456
            ++allocate_.count_;
×
457
        }
×
458
    }
592✔
459

460
    void locality_namespace::counter_data::increment_resolve_locality_count()
×
461
    {
462
        if (resolve_locality_.enabled_)
×
463
        {
464
            ++resolve_locality_.count_;
×
465
        }
×
466
    }
×
467

468
    void locality_namespace::counter_data::increment_free_count()
592✔
469
    {
470
        if (free_.enabled_)
592✔
471
        {
472
            ++free_.count_;
×
473
        }
×
474
    }
592✔
475

476
    void locality_namespace::counter_data::increment_localities_count()
1,439✔
477
    {
478
        if (localities_.enabled_)
1,439✔
479
        {
480
            ++localities_.count_;
×
481
        }
×
482
    }
1,439✔
483

484
    void locality_namespace::counter_data::increment_num_localities_count()
376✔
485
    {
486
        if (num_localities_.enabled_)
376✔
487
        {
488
            ++num_localities_.count_;
×
489
        }
×
490
    }
376✔
491

492
    void locality_namespace::counter_data::increment_num_threads_count()
×
493
    {
494
        if (num_threads_.enabled_)
×
495
        {
496
            ++num_threads_.count_;
×
497
        }
×
498
    }
×
499
}}}    // namespace hpx::agas::server
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc