NewMadeleine

Documentation

« back to PM2 home.
nm_tactics.h
Go to the documentation of this file.
1/*
2 * NewMadeleine
3 * Copyright (C) 2006-2026 (see AUTHORS file)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#ifndef NM_TACTICS_H
17#define NM_TACTICS_H
18
27
29static inline int nm_tactic_req_is_short(const struct nm_req_chunk_s*p_req_chunk)
30{
31 return ( (p_req_chunk->chunk_offset == 0) &&
32 (p_req_chunk->chunk_len < 255) &&
33 (p_req_chunk->chunk_len == p_req_chunk->p_req->pack.len) &&
34 (p_req_chunk->proto_flags == NM_PROTO_FLAG_LASTCHUNK) );
35}
36
38static inline nm_len_t nm_tactic_req_short_size(const struct nm_req_chunk_s*p_req_chunk)
39{
40 assert(nm_tactic_req_is_short(p_req_chunk));
41 return (NM_HEADER_SHORT_DATA_SIZE + p_req_chunk->chunk_len);
42}
43
46static inline nm_len_t nm_tactic_req_data_max_size(const struct nm_req_chunk_s*p_req_chunk)
47{
48 const nm_len_t chunk_len = p_req_chunk->chunk_len;
49 /* compute maximum number of headers for this chunk;
50 * only blocks larger than NM_DATA_IOV_THRESHOLD have their own header */
51 const nm_len_t max_headers = p_req_chunk->chunk_props.size / nm_tactic_get_iov_threshold();
52 const nm_len_t max_header_blocks = (max_headers > p_req_chunk->chunk_props.blocks) ? p_req_chunk->chunk_props.blocks : max_headers;
53 const nm_len_t max_header_len = NM_HEADER_DATA_SIZE + max_header_blocks * sizeof(struct nm_header_pkt_data_chunk_s) + NM_ALIGN_FRONTIER;
54 return (max_header_len + chunk_len);
55}
56
58static inline nm_len_t nm_tactic_req_data_density(const struct nm_req_chunk_s*p_req_chunk)
59{
60 const struct nm_req_s*p_pack = p_req_chunk->p_req;
61 const struct nm_data_properties_s*p_props = nm_data_properties_get(&p_pack->data);
62 const nm_len_t density = (p_props->blocks > 0) ? p_props->size / p_props->blocks : 0;
63 return density;
64}
65
70static inline int nm_tactic_pack_ctrl(nm_gate_t p_gate, nm_drv_t p_drv __attribute__((unused)),
71 struct nm_ctrl_chunk_s*p_ctrl_chunk,
72 struct nm_pkt_wrap_s*p_pw)
73{
74 struct nm_core*p_core = p_gate->p_core;
75 nm_core_lock_assert(p_core);
76 if(NM_HEADER_CTRL_SIZE(&p_ctrl_chunk->ctrl) + p_ctrl_chunk->size < nm_pw_remaining_buf(p_pw))
77 {
78 nm_pw_add_control(p_pw, &p_ctrl_chunk->ctrl, p_ctrl_chunk->p_payload);
79 nm_ctrl_chunk_list_remove(&p_gate->ctrl_chunk_list, p_ctrl_chunk);
80 nm_ctrl_chunk_free(&p_gate->p_core->ctrl_chunk_allocator, p_ctrl_chunk);
81 return NM_ESUCCESS;
82 }
83 else
84 {
85 return -NM_EBUSY;
86 }
87}
88
90 struct nm_req_chunk_list_s*p_req_chunk_list,
91 struct nm_req_chunk_s*p_req_chunk,
92 struct nm_pkt_wrap_s*p_pw);
93
102
103void nm_tactic_rtr_pack(struct nm_core*p_core, struct nm_pkt_wrap_s*p_pw, int nb_chunks, const struct nm_rdv_chunk_s*p_chunks);
104
105void nm_tactic_rdv_accept(struct nm_core*p_core, struct nm_pkt_wrap_s*p_pw);
106
107#endif /* NM_TACTICS_H */
struct nm_core_event_s __attribute__
Definition nm_data.h:530
static const struct nm_data_properties_s * nm_data_properties_get(const struct nm_data_s *p_data)
returns the properties block for the data
Definition nm_data.h:659
@ NM_EBUSY
gate/track is busy
Definition nm_errno.h:47
@ NM_ESUCCESS
successful operation
Definition nm_errno.h:36
#define NM_ALIGN_FRONTIER
assert(p_data->ops.p_traversal !=NULL)
static nm_gate_t p_gate
#define NM_HEADER_SHORT_DATA_SIZE
Definition nm_headers.h:215
#define NM_HEADER_CTRL_SIZE(P_CTRL)
Definition nm_headers.h:218
nm_len_t chunk_len
length of this chunk
Definition nm_headers.h:4
#define NM_PROTO_FLAG_LASTCHUNK
last chunk of data for the given pack
Definition nm_headers.h:50
#define NM_HEADER_DATA_SIZE
Definition nm_headers.h:212
static void nm_core_lock_assert(struct nm_core *p_core)
assert that current thread holds the lock
static nm_len_t nm_pw_remaining_buf(struct nm_pkt_wrap_s *p_pw)
remaining space in pw buffer
int nm_pw_add_control(struct nm_pkt_wrap_s *p_pw, const union nm_header_ctrl_generic_s *p_ctrl, const void *p_payload)
static int nm_tactic_req_is_short(const struct nm_req_chunk_s *p_req_chunk)
checks whether req_chunk is a SHORT chunk for optimized protocol
Definition nm_tactics.h:29
int nm_tactic_pack_rdv(nm_gate_t p_gate, nm_drv_t p_drv, struct nm_req_chunk_list_s *p_req_chunk_list, struct nm_req_chunk_s *p_req_chunk, struct nm_pkt_wrap_s *p_pw)
nm_len_t nm_tactic_get_iov_threshold(void)
get the value of NMAD_DATA_IOV_THRESHOLD
void nm_tactic_rtr_pack(struct nm_core *p_core, struct nm_pkt_wrap_s *p_pw, int nb_chunks, const struct nm_rdv_chunk_s *p_chunks)
static nm_len_t nm_tactic_req_short_size(const struct nm_req_chunk_s *p_req_chunk)
returns size in pw for the given short req_chunk
Definition nm_tactics.h:38
static nm_len_t nm_tactic_req_data_max_size(const struct nm_req_chunk_s *p_req_chunk)
returns max size in pw for given data req_chunk- value is a upper bound, actual size may be lower
Definition nm_tactics.h:46
static int nm_tactic_pack_ctrl(nm_gate_t p_gate, nm_drv_t p_drv __attribute__((unused)), struct nm_ctrl_chunk_s *p_ctrl_chunk, struct nm_pkt_wrap_s *p_pw)
Try to pack a control chunk in a pw.
Definition nm_tactics.h:70
void nm_tactic_rdv_accept(struct nm_core *p_core, struct nm_pkt_wrap_s *p_pw)
static nm_len_t nm_tactic_req_data_density(const struct nm_req_chunk_s *p_req_chunk)
compute average block size
Definition nm_tactics.h:58
int8_t nm_trk_id_t
ID of a track, assigned in order.
Definition nm_types.h:86
uint64_t nm_len_t
data length used by nmad
Definition nm_types.h:68
Core NewMadeleine structure.
Definition nm_core.h:43
struct nm_ctrl_chunk_allocator_s ctrl_chunk_allocator
allocator for control chunks
Definition nm_core.h:70
a chunk of control data
Definition nm_headers.h:194
const void * p_payload
payload for the ctrl chunk (e.g.
Definition nm_headers.h:198
nm_header_ctrl_generic_t ctrl
Definition nm_headers.h:197
nm_len_t size
size of the payload (0 if none)
Definition nm_headers.h:199
block of static properties for a given data descriptor
Definition nm_data.h:93
nm_len_t size
total size in bytes (accumulator)
Definition nm_data.h:95
nm_len_t blocks
number of blocks; -1 if properties are not initialized
Definition nm_data.h:94
a driver.
Definition nm_drv.h:35
Connection to another process.
Definition nm_gate.h:104
struct nm_core * p_core
NM core object.
Definition nm_gate.h:140
struct nm_ctrl_chunk_list_s ctrl_chunk_list
control chunks posted to the gate
Definition nm_gate.h:137
sub-header for pkt_data chunks
Definition nm_headers.h:72
Internal packet wrapper.
a chunk of rdv data.
Definition nm_tactics.h:98
nm_trk_id_t trk_id
trk_id of track to send data on
Definition nm_tactics.h:99
nm_len_t len
length of data chunk
Definition nm_tactics.h:100
a chunk of request
nm_len_t chunk_offset
offset of the chunk relative to the full data in the req
nm_proto_t proto_flags
pre-computed proto flags
struct nm_data_properties_s chunk_props
properties of the data chunk
nm_len_t chunk_len
length of the chunk
struct nm_req_s * p_req
link to insert the req chunk as a core task
a generic pack/unpack request
struct nm_req_s::@15::@17 pack
struct nm_data_s data
data descriptor to send/recv
nm_len_t len
cumulated data length