From patchwork Tue Sep 1 08:49:43 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?THVrw6HFoSBEb2t0b3I=?= X-Patchwork-Id: 45003 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n818nrwg016991 for ; Tue, 1 Sep 2009 08:49:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753240AbZIAItq (ORCPT ); Tue, 1 Sep 2009 04:49:46 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753178AbZIAItq (ORCPT ); Tue, 1 Sep 2009 04:49:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49992 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752782AbZIAIto (ORCPT ); Tue, 1 Sep 2009 04:49:44 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n818njZZ001861; Tue, 1 Sep 2009 04:49:46 -0400 Received: from [10.11.8.174] (vpn-8-174.rdu.redhat.com [10.11.8.174]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n818nhVd024051; Tue, 1 Sep 2009 04:49:44 -0400 Message-ID: <4A9CE027.9050701@redhat.com> Date: Tue, 01 Sep 2009 10:49:43 +0200 From: =?ISO-8859-2?Q?Luk=E1=B9_Doktor?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.1) Gecko/20090814 Fedora/3.0-2.6.b3.fc11 Thunderbird/3.0b3 MIME-Version: 1.0 To: KVM list , Autotest mailing list Subject: Re: [KVM-AUTOTEST PATCH 1/2] Add KSM test References: <4A9B97E5.3000109@redhat.com> <4A9B9956.9000209@redhat.com> In-Reply-To: <4A9B9956.9000209@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org I'm sorry but thunderbird apparently crippled the path. Resending as the attachment. diff --git a/client/tests/kvm/allocator.c b/client/tests/kvm/allocator.c new file mode 100644 index 0000000..89e8ce4 --- /dev/null +++ b/client/tests/kvm/allocator.c @@ -0,0 +1,571 @@ +/* + * KSM test program. + * Copyright(C) 2009 Redhat + * Jason Wang (jasowang@redhat.com) + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//socket linux +#include +#include +#include +#include +//TODO: socket windows + + + +#define PS (4096) +long PAGE_SIZE = PS; +long intInPage = PS/sizeof(int); +#define MAP_FLAGS ( MAP_ANON | MAP_SHARED ) +#define PROT_FLAGS ( PROT_WRITE ) +#define FILE_MODE ( O_RDWR | O_CREAT ) +#define LOG_FILE "/var/log/vksmd" +#define FIFO_FILE "/tmp/vksmd" +#define MODE 0666 +#define FILE_BASE "/tmp/ksm_file" +#define MAX_SIZESIZE 6 +#define MAX_COMMANDSIZE 50 +#define BLOCK_COUNT 8 + +int log_fd = -1; +int base_fd = -1; +int checkvalue = 0; + + +//Socket +struct sockaddr_in sockName; +struct sockaddr_in clientInfo; +int mainSocket,clientSocket; +int port; + +socklen_t addrlen; + + + + +const uint32_t random_mask = UINT32_MAX>>1; +uint32_t random_x = 0; +const uint32_t random_a = 1103515245; +const uint32_t random_m = 2^32; +const uint32_t random_c = 12345; + +int statickey = 0; +int dynamickey = 0; + +typedef enum _COMMANDS +{ + wrongcommad, + ninit, + nrandom, + nexit, + nsrandom, + nsrverify, + nfillzero, + nfillvalue, + ndfill, + nverify +} COMMANDS; + +void sigpipe (int param) +{ + fprintf(stderr,"write error\n"); + //exit(-1); //uncomment end if network connetion is down +} + +int writefull(int socket,char * data,int size){ + int sz = 0; + while (sz < size) + sz += write(socket, data+sz, size-sz); + return sz; +} + + +int write_message(int s,char * message){ + size_t len = strlen(message); + char buf[10]; + sprintf(buf,"%d:",(unsigned int)len); + size_t size = strlen(buf); + + struct timeval tv; + fd_set writeset; + fd_set errorset; + FD_ZERO(&writeset); + FD_ZERO(&errorset); + FD_SET(clientSocket, &writeset); + FD_SET(clientSocket, &errorset); + tv.tv_sec = 0; + tv.tv_usec = 100; + int max = s+1; + tv.tv_sec = 10; + tv.tv_usec = 0; + int ret = select(max, NULL, &writeset, NULL, &tv); + if (ret == -1) + { + return -1; + } + if (ret == 0) + { + return -1; + } + if (FD_ISSET(s, &writeset)) + { + if (writefull(s, buf, size) != size){ + return -1; + } + if (writefull(s, message, len) != len){ + return -1; + } + } + return 0; +} + +void log_info(char *str) +{ + if (write_message(clientSocket, str) != 0){ + fprintf(stderr,"write error\n"); + } +} + +/* fill pages with zero */ +void zero_pages(void **page_array,int npages) +{ + int n = 0; + for(n=0;n 0); + + close(clientSocket); + close(mainSocket); + + if (prev_fn==SIG_IGN) signal (SIGTERM,SIG_IGN); + + return 0; +} + +