77 lines
2.2 KiB
C
77 lines
2.2 KiB
C
/*
|
|
* Copyright (C) 2012 Thomas Preud'homme <thomas.preud-homme@lip6.fr>
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*/
|
|
|
|
#ifndef _FAST_FORWARD_COMMON_H_
|
|
#define _FAST_FORWARD_COMMON_H_ 1
|
|
|
|
/* Non standard include */
|
|
#include <commtech.h>
|
|
#include <assert.h>
|
|
|
|
#ifndef SHARED_SPACE_SIZE
|
|
#define SHARED_SPACE_SIZE (16 * BUF_SIZE)
|
|
#endif
|
|
#define SHARED_SPACE_VOIDPTR (SHARED_SPACE_SIZE / sizeof(void *))
|
|
|
|
#ifndef BUF_SIZE
|
|
#define BUF_SIZE CACHE_LINE_SIZE
|
|
#endif
|
|
|
|
#define DANGER (2 * BUF_SIZE / sizeof(void *))
|
|
#define GOOD (6 * BUF_SIZE / sizeof(void *))
|
|
#define ADJUST_FREQ 64
|
|
|
|
struct channel
|
|
{
|
|
void * volatile *shared_space;
|
|
unsigned int head __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
unsigned int tail __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
};
|
|
|
|
__BEGIN_DECLS
|
|
|
|
extern int adjust_slip(struct channel *channel);
|
|
|
|
static inline void send(struct channel *channel, void **addr)
|
|
{
|
|
static __thread unsigned int nb_iter = 0;
|
|
|
|
assert(addr != NULL);
|
|
if (nb_iter == ADJUST_FREQ)
|
|
{
|
|
adjust_slip(channel);
|
|
nb_iter = 0;
|
|
}
|
|
while (1)
|
|
{
|
|
if (channel->shared_space[channel->head] != NULL)
|
|
continue;
|
|
channel->shared_space[channel->head] = addr;
|
|
channel->head = (channel->head + 1) % SHARED_SPACE_VOIDPTR;
|
|
break;
|
|
}
|
|
}
|
|
|
|
__END_DECLS
|
|
|
|
#endif
|