public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Noah Misch <noah@leadboat.com>
To: cygwin@cygwin.com
Subject: Re: cygserver - Postgres Multiple connection Load Testing - Inifinte Loop
Date: Sun, 02 Apr 2017 02:36:00 -0000	[thread overview]
Message-ID: <20170402023624.GA2561924@tornado.leadboat.com> (raw)
In-Reply-To: <20170328052652.GA2351961@tornado.leadboat.com>

[-- Attachment #1: Type: text/plain, Size: 1161 bytes --]

On Tue, Mar 28, 2017 at 01:26:52AM -0400, Noah Misch wrote:
> On Fri, Mar 24, 2017 at 06:11:01PM +0100, Corinna Vinschen wrote:
> > I pushed a patchset now, and uploaded new developer snapshots for
> > testing to https://cygwin.com/snapshots/
> 
> > Please give it a try

> I call the cygwin-20170324 freezes "limited" because the symptoms differ from
> the classic freeze I described upthread.  "strace /bin/true" and "cat
> /proc/sysvipc/sem" do not hang, but every PostgreSQL backend process is stuck
> waiting on a synchronization primitive.
> 
> I can distill another self-contained test case for the limited freeze seen in
> cygwin-20170324, but that make take awhile.  I'm sending this early report so
> you're aware of the possible regression in cygwin-20170324.

I'm attaching a new test program that demonstrates the regression.  My previous
test program created sixteen processes that each picked a random semaphore to
lock.  Now, each process picks two semaphores and locks them in order.  This
proceeds smoothly on GNU/Linux and on cygwin-20170321.tar.xz "cygserver -r 40".
It freezes within one second on cygwin-20170324.tar.xz "cygserver -r 40".

[-- Attachment #2: sema_two.c --]
[-- Type: text/plain, Size: 3009 bytes --]

/*
 * Demonstrate cygserver bug introduced in cygwin-20170324.tar.xz snapshot.  Run
 * without arguments.  Test against "cygserver -r 40" to get enough threads.
 * This is otherwise compatible with default cygserver settings; it uses a
 * single semaphore set of eight semaphores.
 *
 * Output will cease within a few seconds.  On older cygserver and non-Cygwin
 * systems, it will run to completion.
 */

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#define SEM_KEY 0x631a2c3f
#define N_WORKER 16
#define N_SEMA (N_WORKER/2)
#define N_CYCLE 1000000

union semun
{
    int val;
    struct semid_ds *buf;
    unsigned short *array;
};

static int print_every = 1;


static int lock(int set, unsigned short sem_num)
{
    struct sembuf op;
    op.sem_num = sem_num;
    op.sem_op = -1;
    op.sem_flg = 0;
    if (0 > semop(set, &op, 1))
    {
	perror("semop");
	return 1;
    }
    return 0;
}

static int unlock(int set, unsigned short sem_num)
{
    struct sembuf op;
    op.sem_num = sem_num;
    op.sem_op = 1 ;		/* only difference vs. lock() */
    op.sem_flg = 0;
    if (0 > semop(set, &op, 1))
    {
	perror("semop");
	return 1;
    }
    return 0;
}

/* In parallel, N_WORKER processes run this function. */
static int do_worker(int ordinal, int set)
{
    int i;

    printf("start worker %d\n", ordinal);
    fflush(stdout);

    for (i = 1; i <= N_CYCLE; i++)
    {
	unsigned short s0, s1;

	/* Pick two non-identical semaphore numbers. */
	s0 = random() % N_SEMA;
	do { s1 = random() % N_SEMA; } while (s0 == s1);

	/* Lock the lower one first, thereby preventing deadlock. */
	if (lock(set, s0 < s1 ? s0 : s1) || lock(set, s0 < s1 ? s1 : s0)
	    || unlock(set, s0) || unlock(set, s1))
	    return 1;

	if (i % print_every == 0)
	{
	    printf("worker %d: %d cycles elapsed\n", ordinal, i);
	    fflush(stdout);
	}
    }

    return 0;
}

int main(int argc, char **argv)
{
    int status = 1, set, i, child_status;

    if (argc == 2)
	print_every = atoi(argv[1]);
    else if (argc != 1)
    {
	fprintf(stderr, "Usage: sema_two [print-every-N]\n");
	return status;
    }

    puts("semget");
    fflush(stdout);
    set = semget(SEM_KEY, N_SEMA, IPC_CREAT | 0600);
    if (set == -1)
    {
	perror("semget");
	return status;
    }

    puts("SETVAL");
    fflush(stdout);
    for (i = 0; i < N_SEMA; i++)
    {
	union semun s;
	s.val = 1;

	if (0 > semctl(set, i, SETVAL, s))
	{
	    perror("semctl(SETVAL)");
	    goto cleanup;
	}
    }

    for (i = 0; i < N_WORKER; i++)
    {
	pid_t pid;
	pid = fork();
	switch (pid)
	{
	    case -1:
		perror("fork");
		goto cleanup;
	    case 0:
		return do_worker(i, set);
	}
    }

    status = 0;

cleanup:
    while (wait(&child_status) != -1)
	;
    if (errno != ECHILD)
    {
	perror("wait");
	status = 1;
    }

    if (0 > semctl(set, 0, IPC_RMID))
    {
	perror("semtctl(IPC_RMID)");
	status = 1;
    }

    return status;
}


[-- Attachment #3: Type: text/plain, Size: 219 bytes --]


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

  reply	other threads:[~2017-04-02  2:36 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200408030333.i733XEXn023894@mx3.redhat.com>
2004-08-03 10:06 ` Corinna Vinschen
2004-08-03 20:45   ` Saravanan Bellan
2004-08-03 20:54     ` Christopher Faylor
2004-08-03 21:10       ` Saravanan Bellan
2017-03-21  2:56   ` Noah Misch
2017-03-21  7:29     ` Marco Atzeri
2017-03-24 17:52     ` Corinna Vinschen
2017-03-25 10:55       ` Marco Atzeri
2017-03-25 12:02         ` Corinna Vinschen
2017-03-25 12:31           ` Marco Atzeri
2017-03-28  5:48       ` Noah Misch
2017-04-02  2:36         ` Noah Misch [this message]
2017-05-07  3:35           ` Noah Misch
2017-05-07  4:01             ` Larry Hall (Cygwin)
2017-06-14 23:32               ` Marco Atzeri
2017-06-20 11:11                 ` Corinna Vinschen
2017-06-20 17:29                   ` Marco Atzeri
2017-06-21  7:58                     ` Corinna Vinschen
2004-08-03  3:33 sarbx-cygwin6344
     [not found] <200407302132.i6ULWwXn016838@mx3.redhat.com>
2004-08-02  9:45 ` Corinna Vinschen
  -- strict thread matches above, loose matches on Subject: below --
2004-07-30 22:09 sarbx-cygwin6344
     [not found] <200407290319.i6T3JCXn018245@mx3.redhat.com>
2004-07-30 13:43 ` Corinna Vinschen
2004-07-29 10:35 sarbx-cygwin6344

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=20170402023624.GA2561924@tornado.leadboat.com \
    --to=noah@leadboat.com \
    --cc=cygwin@cygwin.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).