From: Hans Henrik Happe <hhh@imada.sdu.dk>
To: Avi Kivity <avi@argo.co.il>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Issues with INET sockets through loopback (lo)
Date: Tue, 31 May 2005 18:18:44 +0200 [thread overview]
Message-ID: <200505311818.44938.hhh@imada.sdu.dk> (raw)
In-Reply-To: <1116937382.1848.9.camel@blast.qumranet.com>
[-- Attachment #1: Type: text/plain, Size: 650 bytes --]
On Tuesday 24 May 2005 14:23, Avi Kivity wrote:
> On Mon, 2005-05-23 at 13:17 +0200, Hans Henrik Happe wrote:
>
> > I hope that others can comfirm that this is an issue or otherwise explain
> > why it is supposed behave this way.
> >
>
> you might try using udp instead of tcp. this would help determine
> whether the problem is in the tcp stack or the loopback interface.
Now I have tried with SCTP and it works great (no idle CPU time).
So my guess is still that there is a problem in TCP.
I have attached the SCTP program. It's my first attempt at using SCTP, so it's
not beautiful. The messages get around as expected though.
TripleH ;-)
[-- Attachment #2: random-sctp.c --]
[-- Type: text/x-csrc, Size: 3533 bytes --]
/*
* usage: random-inet <# processes> <# messages>
*/
#include <asm/msr.h>
#include <stdio.h>
#include <poll.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/sctp.h>
typedef struct {
struct sockaddr sockadr;
int len;
} adr_t;
int get_adr(adr_t *adr, int port) {
int n;
struct addrinfo hints, *res;
char str[6];
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
sprintf(str, "%d", port);
n = getaddrinfo("localhost", str, &hints, &res);
if (n != 0) {
fprintf(stderr,
"getaddrinfo error: [%s]\n",
gai_strerror(n));
return -1;
}
memcpy(&adr->sockadr, res->ai_addr, sizeof(*res->ai_addr));
adr->len = sizeof(*res->ai_addr);
freeaddrinfo(res);
return 0;
}
int init_listen(int port) {
int n, on=1;
int sock;
struct sockaddr_in name;
sock = socket(PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
if (sock == -1) {
perror("socket");
return -1;
}
name.sin_family = PF_INET;
name.sin_port = htons (port);
name.sin_addr.s_addr = htonl (INADDR_ANY);
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) == -1) {
perror("bind");
return -1;
}
if (listen(sock, 10) == -1) {
perror("listen");
return -1;
}
return sock;
}
int do_recv(int sock, void *buf, int n) {
struct sockaddr sa;
struct sctp_sndrcvinfo info;
int slen, flags;
slen = sizeof(sa);
n = sctp_recvmsg(sock, buf, n, &sa, &slen, &info, &flags);
// n = sctp_recvmsg(sock, buf, n, &sa, &slen, &info, &flags);
if (n == -1) {
perror("recv");
}
return n;
}
int do_send(int sock, adr_t *adr, void *buf, int n) {
n = sctp_sendmsg(sock, buf, n, &adr->sockadr, adr->len, 666, MSG_ADDR_OVER, 0, 0, 444);
if (n == -1) {
perror("send");
}
return n;
}
int main(int argc, char *argv[]) {
int i, n, cnt, pid, dest;
int lsock;
char data, id, rank;
int port = 11100;
uint64_t t0, t1;
/* # processes */
cnt = atoi(argv[1]);
/* # messages */
n = atoi(argv[2]);
{
adr_t dests[cnt];
/* Create processes */
rank = 0;
for (i=1; i<cnt; i++) {
pid = fork();
if (pid == 0) {
rank=cnt-i;
break;
}
}
/* Setup connections */
lsock = init_listen(port+rank);
sleep(2); /* "Ensure" that all processes are listening, HACK!!! */
for (i=0; i<cnt; i++) {
get_adr(dests+i, port+i);
}
srandom(rank);
/* Write startup messages */
if (rank < n) {
do_send(lsock, &dests[(rank+1)%cnt], &data, 1);
}
sleep(1);
/* Receive and forward messages to random destinations */
while (1) {
do_recv(lsock, &data, 1);
dest = random()%cnt;
/* Do not send to self */
if (dest == rank) {
dest = (dest+1)%cnt;
}
do_send(lsock, &dests[dest], &data, 1);
}
}
return 0;
}
prev parent reply other threads:[~2005-05-31 16:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-05-23 11:17 Hans Henrik Happe
2005-05-23 12:09 ` DervishD
2005-05-24 12:12 ` Hans Henrik Happe
2005-05-24 12:23 ` Avi Kivity
2005-05-31 16:18 ` Hans Henrik Happe [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200505311818.44938.hhh@imada.sdu.dk \
--to=hhh@imada.sdu.dk \
--cc=avi@argo.co.il \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome