kpacket_gen: use constants for cmdlength
[cor.git] / net / cor / credits.c
blob5dc38ad58274465f1a1996699cde004258aac551
1 /**
2 * Connection oriented routing
3 * Copyright (C) 2007-2012 Michael Blizek
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA.
20 #include "cor.h"
24 int newconn_checkpriority(struct neighbor *nb, __u8 priority)
26 // if(num_conns >= MAX_CONNS) ...
27 #warning todo reset other conn
28 return 0;
31 __u32 refresh_conn_priority(struct conn *cn, int locked)
33 __u32 priority = 0;
34 __u8 priority_last;
35 __u8 priority_enc;
38 if (likely(locked == 0)) {
39 if (cn->is_client == 0)
40 return refresh_conn_priority(cn->reversedir, 0);
42 spin_lock_bh(&(cn->rcv_lock));
43 spin_lock_bh(&(cn->reversedir->rcv_lock));
47 if (unlikely(cn->isreset != 0))
48 goto out;
50 if (cn->targettype != TARGET_OUT) {
51 priority = 0;
52 goto out;
55 if (cn->sourcetype == SOURCE_IN) {
56 __u64 priority_sum =
57 atomic64_read(&(
58 cn->source.in.nb->priority_sum));
59 if (priority_sum > PRIORITY_MAX) {
60 priority = div_u64(((__u64) cn->source.in.priority) *
61 PRIORITY_MAX, priority_sum);
62 } else {
63 priority = cn->source.in.priority;
65 } else if (cn->sourcetype == SOURCE_SOCK) {
66 priority = cn->source.sock.priority;
67 } else {
68 BUG();
71 if (cn->target.out.priority_send_allowed == 0)
72 goto out;
74 priority_enc = enc_log_256_16(priority);
76 priority_last = cn->target.out.priority_last;
77 if (priority_enc != priority_last) {
78 int force = (priority_enc != priority_last + 1 &&
79 priority_enc != priority_last - 1);
80 send_priority(cn, force, priority_enc);
83 out:
84 if (likely(locked == 0)) {
85 spin_unlock_bh(&(cn->reversedir->rcv_lock));
86 spin_unlock_bh(&(cn->rcv_lock));
89 return priority;
92 static void _set_conn_in_priority(struct conn *src_in_lx, __u32 newpriority)
94 struct neighbor *nb = src_in_lx->source.in.nb;
96 __u32 oldpriority = src_in_lx->source.in.priority;
98 update_atomic_sum(&(nb->priority_sum),
99 oldpriority, newpriority);
101 src_in_lx->source.in.priority = newpriority;
104 void set_conn_in_priority(struct neighbor *nb, __u32 conn_id,
105 struct conn *src_in, __u8 priority_seqno, __u8 priority)
107 __u32 newpriority;
109 if (unlikely(src_in->is_client == 0))
110 return;
112 spin_lock_bh(&(src_in->rcv_lock));
113 spin_lock_bh(&(src_in->reversedir->rcv_lock));
115 if (unlikely(is_conn_in(src_in, nb, conn_id) == 0))
116 goto out;
118 if (src_in->source.in.priority_seqno != priority_seqno)
119 goto out;
120 src_in->source.in.priority_seqno++;
122 newpriority = (dec_log_256_16(priority)*4)/5;
123 _set_conn_in_priority(src_in, newpriority);
124 refresh_conn_priority(src_in, 1);
126 out:
127 spin_unlock_bh(&(src_in->reversedir->rcv_lock));
128 spin_unlock_bh(&(src_in->rcv_lock));
131 void connreset_priority(struct conn *cn_lx)
133 if (cn_lx->is_client == 0)
134 return;
136 if (cn_lx->sourcetype == SOURCE_IN)
137 _set_conn_in_priority(cn_lx, 0);
140 int __init credits_init(void)
142 return 0;
145 MODULE_LICENSE("GPL");