From owner-svn-src-user@FreeBSD.ORG Sun Jan 24 02:10:23 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B0D2E1065672; Sun, 24 Jan 2010 02:10:23 +0000 (UTC) (envelope-from dougb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 953B88FC16; Sun, 24 Jan 2010 02:10:23 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0O2AN4j086218; Sun, 24 Jan 2010 02:10:23 GMT (envelope-from dougb@svn.freebsd.org) Received: (from dougb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0O2ANY9086216; Sun, 24 Jan 2010 02:10:23 GMT (envelope-from dougb@svn.freebsd.org) Message-Id: <201001240210.o0O2ANY9086216@svn.freebsd.org> From: Doug Barton Date: Sun, 24 Jan 2010 02:10:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r202906 - user/dougb/portmaster X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Jan 2010 02:10:23 -0000 Author: dougb Date: Sun Jan 24 02:10:23 2010 New Revision: 202906 URL: http://svn.freebsd.org/changeset/base/202906 Log: Remove the RCS Id stuff since I'm not using that currently, and not likely to go back. Add a --no-confirm option to suppress the new feature of confirming the work to be done before doing it. Tune up the confirmation message. Don't bother confirming if the only thing to be done is the exact work that the user specified on the command line. Modified: user/dougb/portmaster/portmaster Modified: user/dougb/portmaster/portmaster ============================================================================== --- user/dougb/portmaster/portmaster Sun Jan 24 01:06:02 2010 (r202905) +++ user/dougb/portmaster/portmaster Sun Jan 24 02:10:23 2010 (r202906) @@ -42,16 +42,14 @@ umask 022 version () { local rcs cvs - rcs='$Id: portmaster,v 2.54 2009/09/15 07:50:11 dougb Exp $' cvs='$FreeBSD$' - rcs="${rcs#*,v }" ; rcs="${rcs%% *}" cvs="${cvs#*,v }" ; cvs="${cvs#*/portmaster }" ; cvs="${cvs%% *}" echo '' [ "${cvs#$}" != 'FreeBSD$' ] && { echo "===>>> Version $cvs" ; return 0; } - echo "===>>> Development version $rcs" + echo "===>>> Version unknown!" } fail () { @@ -242,7 +240,7 @@ usage () { echo "Common flags: [--force-config] [-CGHKgntvw B|b f|i D|d]" echo " [[--packages|--packages-only] [-P|-PP] | [--packages-build]]" echo " [--packages-if-newer] [--delete-build-only] [--always-fetch]" - echo " [--local-packagedir=]" + echo " [--local-packagedir=] [--no-confirm]" echo " [-m ] [-x ]" echo "${0##*/} [Common flags] " echo "${0##*/} [Common flags] " @@ -298,6 +296,8 @@ usage () { echo "-m " echo "-x " echo ' Can be specified more than once' + echo '--no-confirm do not ask user to confirm list of ports to be' + echo ' installed and/or updated before proceeding' echo '' echo '--show-work list what ports are and would be installed' echo '' @@ -436,6 +436,8 @@ for var in "$@" ; do -[A-Za-z0-9]*) newopts="$newopts $var" ;; --delete-build-only) PM_DEL_BUILD_ONLY=pm_dbo export PM_DEL_BUILD_ONLY ;; + --no-confirm) PM_NO_CONFIRM=pm_no_confirm + export PM_NO_CONFIRM ;; --help) usage 0 ;; --version) version ; exit 0 ;; --clean-distfiles) CLEAN_DISTFILES=clean_distfiles ;; @@ -1944,18 +1946,24 @@ create_master_rb_list () { post_config () { local numdeps answer action - [ $num_of_deps -gt 0 ] && numdeps=" (${num_of_deps})" - term_printf "$numdeps" + if [ $num_of_deps -gt 0 ]; then + numdeps=" (${num_of_deps})" + term_printf "$numdeps" - echo '' - echo "===>>> If you choose to proceed, the following will be done:" - echo -e "$build_l" - echo -n "===>>> Proceed? y/n [y] " - read answer - case "$answer" in - [nN]*) safe_exit ;; - esac - unset build_l + if [ -z "$PM_NO_CONFIRM" ]; then + echo '' +echo "===>>> The following actions will be taken if you choose to proceed:" + echo -e "$build_l" + echo -n "===>>> Proceed? y/n [y] " + read answer + case "$answer" in + [nN]*) safe_exit ;; + esac + unset build_l + fi + else + term_printf + fi action=build if [ "$PM_PACKAGES" = only ]; then From owner-svn-src-user@FreeBSD.ORG Sun Jan 24 02:33:14 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 58190106566C; Sun, 24 Jan 2010 02:33:14 +0000 (UTC) (envelope-from dougb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4764B8FC0A; Sun, 24 Jan 2010 02:33:14 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0O2XEmf091217; Sun, 24 Jan 2010 02:33:14 GMT (envelope-from dougb@svn.freebsd.org) Received: (from dougb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0O2XEOg091215; Sun, 24 Jan 2010 02:33:14 GMT (envelope-from dougb@svn.freebsd.org) Message-Id: <201001240233.o0O2XEOg091215@svn.freebsd.org> From: Doug Barton Date: Sun, 24 Jan 2010 02:33:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r202907 - user/dougb/portmaster X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Jan 2010 02:33:14 -0000 Author: dougb Date: Sun Jan 24 02:33:14 2010 New Revision: 202907 URL: http://svn.freebsd.org/changeset/base/202907 Log: When I was twiddling update_port() previously I forgot to restore a test for the presence of the $update_to argument. The effect was cosmetic, but needed to be fixed. In post_config(), simplify some of the new code related to the terminal title string, and move a local statement down inside the test where the variable will be used. Modified: user/dougb/portmaster/portmaster Modified: user/dougb/portmaster/portmaster ============================================================================== --- user/dougb/portmaster/portmaster Sun Jan 24 02:10:23 2010 (r202906) +++ user/dougb/portmaster/portmaster Sun Jan 24 02:33:14 2010 (r202907) @@ -1685,7 +1685,7 @@ update_build_l () { update_port () { local update_to - update_to=" to $2" + [ -n "$2" ] && update_to=" to $2" echo "===>>> Launching child to update ${1#$pd/}${update_to}" dep_of_deps=$(( $dep_of_deps + 1 )) @@ -1944,13 +1944,14 @@ create_master_rb_list () { } post_config () { - local numdeps answer action + local action if [ $num_of_deps -gt 0 ]; then - numdeps=" (${num_of_deps})" - term_printf "$numdeps" + term_printf " (${num_of_deps})" if [ -z "$PM_NO_CONFIRM" ]; then + local answer + echo '' echo "===>>> The following actions will be taken if you choose to proceed:" echo -e "$build_l" From owner-svn-src-user@FreeBSD.ORG Sun Jan 24 05:23:08 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9E182106566B; Sun, 24 Jan 2010 05:23:08 +0000 (UTC) (envelope-from dougb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8D5628FC0C; Sun, 24 Jan 2010 05:23:08 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0O5N80u028778; Sun, 24 Jan 2010 05:23:08 GMT (envelope-from dougb@svn.freebsd.org) Received: (from dougb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0O5N8PI028776; Sun, 24 Jan 2010 05:23:08 GMT (envelope-from dougb@svn.freebsd.org) Message-Id: <201001240523.o0O5N8PI028776@svn.freebsd.org> From: Doug Barton Date: Sun, 24 Jan 2010 05:23:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r202910 - user/dougb/portmaster X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Jan 2010 05:23:08 -0000 Author: dougb Date: Sun Jan 24 05:23:08 2010 New Revision: 202910 URL: http://svn.freebsd.org/changeset/base/202910 Log: Update copyright Document the --no-confirm option Attempt to improve readability by re-sorting and rewording a few of the paragraphs. Modified: user/dougb/portmaster/portmaster.8 Modified: user/dougb/portmaster/portmaster.8 ============================================================================== --- user/dougb/portmaster/portmaster.8 Sun Jan 24 03:10:48 2010 (r202909) +++ user/dougb/portmaster/portmaster.8 Sun Jan 24 05:23:08 2010 (r202910) @@ -1,4 +1,4 @@ -.\" Copyright (c) 2006-2009 Doug Barton dougb@FreeBSD.org +.\" Copyright (c) 2006-2010 Doug Barton dougb@FreeBSD.org .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd December 3, 2009 +.Dd January 23, 2010 .Dt PORTMASTER 8 .Os .Sh NAME @@ -38,6 +38,7 @@ Common Flags: .Op Fl -delete-build-only .Op Fl -always-fetch .Op Fl -local-packagedir= +.Op Fl -no-confirm .Op Fl m Ar arguments for make .Op Fl x Ar glob pattern to exclude from building .Nm @@ -133,7 +134,7 @@ including what is located in .Pa /var/db/pkg . The focus of this tool is to keep the dependency tracking information for your ports up to date. -This allows you to update a specific port without +This allows you to safely update a specific port without having to update all of the ports .Qq above it. @@ -145,7 +146,8 @@ option exists to accomplish this. .Pp By default .Nm -updates the port you specify on the command line +updates the port you specify on the command line. +This will occur whether there is a new version for it or not. It will first recurse through the port and all of its dependencies (if any) to handle @@ -156,25 +158,38 @@ or if the OPTIONS have changed. You can force dialogs for all ports by using the .Fl -force-config option. -It will then start building all ports that need -updating. +.Pp While recursing through dependencies, if you are not using any of the .Fl -packages* options, a 'make checksum' process will be launched in the background to either verify that the -correct distfiles are available, +correct distfiles are available or start downloading the new ones. If you stop .Nm with ^C, an attempt will be made to kill off the child processes started for this purpose. .Pp -If the recursion through the ports for 'make -config' does not find a port that needs updating -the dependency check step will be skipped prior -to building the port specified on the command line. +While checking dependencies if a port has CONFLICTS +set they will be compared to your installed ports +and if you already have an alternate version of the dependency +that is required by the port you are building +it will be used in place of the default dependency. +.Pp +When the config and dependency checking phase is over the +user will be presented with a list of ports that will be +installed and/or upgraded, and asked to approve +before proceeding. +This behavior can be supressed with the +.Fl -no-confirm +option. +.Pp +If the dependency check +does not find a port that needs updating +that step will be skipped prior +to building the port(s) specified on the command line. In addition to this optimization, information about up-to-date dependencies, choices made on which ports to build for @@ -196,12 +211,6 @@ or .Fl D options. .Pp -While checking dependencies, if a port has CONFLICTS -set, the list will be checked against your installed ports, -and if you have installed an alternate version of a port -that is required by the port you are building, -it will be used in place of the default dependency. -.Pp There are a number of .Fl -packages* options available to save the time that would normally @@ -292,11 +301,6 @@ The answer is that (unfortunately) is not omniscient, and cannot guess what resolution the user would like to have for this problem. Manual intervention is therefore required. -Assuming that the failure occurred after the config phase has ended -(i.e., something has started building), -the user can save time by adding the -.Fl G -option to the command line to skip the config phase the second time through. .Sh OPTIONS The options are as follows: .Bl -tag -width F1 @@ -406,6 +410,9 @@ in the category subdirectories, such as .Pa /devel , .Pa /ports-mgmt , etc. +.It Fl -no-confirm +do not ask the user to confirm the list of ports to +be installed and/or updated before proceeding .It Fl l list all installed ports by category .It Fl L @@ -595,6 +602,9 @@ along with their related options. # # Specify a local package repository (--local-packagedir) # LOCAL_PACKAGEDIR= +# +# Suppress the build confirmation message (--no-confirm) +# PM_NO_CONFIRM=pm_no_confirm .Ed .Pp .It Pa /var/db/pkg/*/+IGNOREME From owner-svn-src-user@FreeBSD.ORG Sun Jan 24 09:02:38 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8CD3A106566B; Sun, 24 Jan 2010 09:02:38 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 79F058FC0C; Sun, 24 Jan 2010 09:02:38 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0O92c02077897; Sun, 24 Jan 2010 09:02:38 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0O92ctR077887; Sun, 24 Jan 2010 09:02:38 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <201001240902.o0O92ctR077887@svn.freebsd.org> From: Kip Macy Date: Sun, 24 Jan 2010 09:02:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r202912 - in user/kmacy/releng_8_rump/lib/libunet: . include include/amd64 include/amd64/include include/sys test unet_sys X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Jan 2010 09:02:38 -0000 Author: kmacy Date: Sun Jan 24 09:02:38 2010 New Revision: 202912 URL: http://svn.freebsd.org/changeset/base/202912 Log: - do pcpu initialization - make curthread work - skip module registration Added: user/kmacy/releng_8_rump/lib/libunet/include/amd64/ user/kmacy/releng_8_rump/lib/libunet/include/amd64/include/ user/kmacy/releng_8_rump/lib/libunet/include/amd64/include/pcpu.h (contents, props changed) user/kmacy/releng_8_rump/lib/libunet/include/machine (contents, props changed) user/kmacy/releng_8_rump/lib/libunet/include/sys/pcpu.h (contents, props changed) Modified: user/kmacy/releng_8_rump/lib/libunet/Makefile user/kmacy/releng_8_rump/lib/libunet/test/init.c user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_compat.c user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_glue.c user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_kern_intr.c user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_kern_synch.c Modified: user/kmacy/releng_8_rump/lib/libunet/Makefile ============================================================================== --- user/kmacy/releng_8_rump/lib/libunet/Makefile Sun Jan 24 08:59:33 2010 (r202911) +++ user/kmacy/releng_8_rump/lib/libunet/Makefile Sun Jan 24 09:02:38 2010 (r202912) @@ -13,11 +13,11 @@ LIB= unet UNET_KERN_COMMON_OBJS += \ kern_environment.o \ kern_mbuf.o \ - kern_module.o \ kern_mtxpool.o \ kern_sysctl.o \ md5c.o \ subr_eventhandler.o \ + subr_kobj.o \ subr_lock.o \ subr_param.o \ subr_pcpu.o \ @@ -89,7 +89,7 @@ UNET_OTHER_COMMON_OBJS = \ UNET_GLUE_COMMON_OBJS = \ unet_compat.o \ unet_glue.o \ - unet_in_cksum.o \ + unet_in_cksum.o \ unet_init_main.o \ unet_lock.o \ unet_kern_condvar.o \ Added: user/kmacy/releng_8_rump/lib/libunet/include/amd64/include/pcpu.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/kmacy/releng_8_rump/lib/libunet/include/amd64/include/pcpu.h Sun Jan 24 09:02:38 2010 (r202912) @@ -0,0 +1,236 @@ +/*- + * Copyright (c) Peter Wemm + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_PCPU_H_ +#define _MACHINE_PCPU_H_ + +#ifndef _SYS_CDEFS_H_ +#error "sys/cdefs.h is a prerequisite for this file" +#endif + +#if defined(XEN) || defined(XENHVM) +#ifndef NR_VIRQS +#define NR_VIRQS 24 +#endif +#ifndef NR_IPIS +#define NR_IPIS 2 +#endif +#endif + +#ifdef XENHVM +#define PCPU_XEN_FIELDS \ + ; \ + unsigned int pc_last_processed_l1i; \ + unsigned int pc_last_processed_l2i +#else +#define PCPU_XEN_FIELDS +#endif + +/* + * The SMP parts are setup in pmap.c and locore.s for the BSP, and + * mp_machdep.c sets up the data for the AP's to "see" when they awake. + * The reason for doing it via a struct is so that an array of pointers + * to each CPU's data can be set up for things like "check curproc on all + * other processors" + */ +#define PCPU_MD_FIELDS \ + char pc_monitorbuf[128] __aligned(128); /* cache line */ \ + struct pcpu *pc_prvspace; /* Self-reference */ \ + struct pmap *pc_curpmap; \ + struct amd64tss *pc_tssp; /* TSS segment active on CPU */ \ + struct amd64tss *pc_commontssp;/* Common TSS for the CPU */ \ + register_t pc_rsp0; \ + register_t pc_scratch_rsp; /* User %rsp in syscall */ \ + u_int pc_apic_id; \ + u_int pc_acpi_id; /* ACPI CPU id */ \ + /* Pointer to the CPU %fs descriptor */ \ + struct user_segment_descriptor *pc_fs32p; \ + /* Pointer to the CPU %gs descriptor */ \ + struct user_segment_descriptor *pc_gs32p; \ + /* Pointer to the CPU LDT descriptor */ \ + struct system_segment_descriptor *pc_ldt; \ + /* Pointer to the CPU TSS descriptor */ \ + struct system_segment_descriptor *pc_tss \ + PCPU_XEN_FIELDS + +#ifdef _KERNEL + +#ifdef lint + +extern struct pcpu *pcpup; + +#define PCPU_GET(member) (pcpup->pc_ ## member) +#define PCPU_ADD(member, val) (pcpup->pc_ ## member += (val)) +#define PCPU_INC(member) PCPU_ADD(member, 1) +#define PCPU_PTR(member) (&pcpup->pc_ ## member) +#define PCPU_SET(member, val) (pcpup->pc_ ## member = (val)) + +#elif defined(__GNUCLIKE_ASM) && defined(__GNUCLIKE___TYPEOF) + +/* + * Evaluates to the byte offset of the per-cpu variable name. + */ +#define __pcpu_offset(name) \ + __offsetof(struct pcpu, name) + +/* + * Evaluates to the type of the per-cpu variable name. + */ +#define __pcpu_type(name) \ + __typeof(((struct pcpu *)0)->name) + +/* + * Evaluates to the address of the per-cpu variable name. + */ +#define __PCPU_PTR(name) __extension__ ({ \ + __pcpu_type(name) *__p; \ + \ + __asm __volatile("movq %%gs:%1,%0; addq %2,%0" \ + : "=r" (__p) \ + : "m" (*(struct pcpu *)(__pcpu_offset(pc_prvspace))), \ + "i" (__pcpu_offset(name))); \ + \ + __p; \ +}) + +/* + * Evaluates to the value of the per-cpu variable name. + */ +#define __PCPU_GET(name) __extension__ ({ \ + __pcpu_type(name) __res; \ + struct __s { \ + u_char __b[MIN(sizeof(__pcpu_type(name)), 8)]; \ + } __s; \ + \ + if (sizeof(__res) == 1 || sizeof(__res) == 2 || \ + sizeof(__res) == 4 || sizeof(__res) == 8) { \ + __asm __volatile("mov %%gs:%1,%0" \ + : "=r" (__s) \ + : "m" (*(struct __s *)(__pcpu_offset(name)))); \ + *(struct __s *)(void *)&__res = __s; \ + } else { \ + __res = *__PCPU_PTR(name); \ + } \ + __res; \ +}) + +/* + * Adds the value to the per-cpu counter name. The implementation + * must be atomic with respect to interrupts. + */ +#define __PCPU_ADD(name, val) do { \ + __pcpu_type(name) __val; \ + struct __s { \ + u_char __b[MIN(sizeof(__pcpu_type(name)), 8)]; \ + } __s; \ + \ + __val = (val); \ + if (sizeof(__val) == 1 || sizeof(__val) == 2 || \ + sizeof(__val) == 4 || sizeof(__val) == 8) { \ + __s = *(struct __s *)(void *)&__val; \ + __asm __volatile("add %1,%%gs:%0" \ + : "=m" (*(struct __s *)(__pcpu_offset(name))) \ + : "r" (__s)); \ + } else \ + *__PCPU_PTR(name) += __val; \ +} while (0) + +/* + * Increments the value of the per-cpu counter name. The implementation + * must be atomic with respect to interrupts. + */ +#define __PCPU_INC(name) do { \ + CTASSERT(sizeof(__pcpu_type(name)) == 1 || \ + sizeof(__pcpu_type(name)) == 2 || \ + sizeof(__pcpu_type(name)) == 4 || \ + sizeof(__pcpu_type(name)) == 8); \ + if (sizeof(__pcpu_type(name)) == 1) { \ + __asm __volatile("incb %%gs:%0" \ + : "=m" (*(__pcpu_type(name) *)(__pcpu_offset(name)))\ + : "m" (*(__pcpu_type(name) *)(__pcpu_offset(name))));\ + } else if (sizeof(__pcpu_type(name)) == 2) { \ + __asm __volatile("incw %%gs:%0" \ + : "=m" (*(__pcpu_type(name) *)(__pcpu_offset(name)))\ + : "m" (*(__pcpu_type(name) *)(__pcpu_offset(name))));\ + } else if (sizeof(__pcpu_type(name)) == 4) { \ + __asm __volatile("incl %%gs:%0" \ + : "=m" (*(__pcpu_type(name) *)(__pcpu_offset(name)))\ + : "m" (*(__pcpu_type(name) *)(__pcpu_offset(name))));\ + } else if (sizeof(__pcpu_type(name)) == 8) { \ + __asm __volatile("incq %%gs:%0" \ + : "=m" (*(__pcpu_type(name) *)(__pcpu_offset(name)))\ + : "m" (*(__pcpu_type(name) *)(__pcpu_offset(name))));\ + } \ +} while (0) + +/* + * Sets the value of the per-cpu variable name to value val. + */ +#define __PCPU_SET(name, val) { \ + __pcpu_type(name) __val; \ + struct __s { \ + u_char __b[MIN(sizeof(__pcpu_type(name)), 8)]; \ + } __s; \ + \ + __val = (val); \ + if (sizeof(__val) == 1 || sizeof(__val) == 2 || \ + sizeof(__val) == 4 || sizeof(__val) == 8) { \ + __s = *(struct __s *)(void *)&__val; \ + __asm __volatile("mov %1,%%gs:%0" \ + : "=m" (*(struct __s *)(__pcpu_offset(name))) \ + : "r" (__s)); \ + } else { \ + *__PCPU_PTR(name) = __val; \ + } \ +} + +#define PCPU_GET(member) __PCPU_GET(pc_ ## member) +#define PCPU_ADD(member, val) __PCPU_ADD(pc_ ## member, val) +#define PCPU_INC(member) __PCPU_INC(pc_ ## member) +#define PCPU_PTR(member) __PCPU_PTR(pc_ ## member) +#define PCPU_SET(member, val) __PCPU_SET(pc_ ## member, val) + +extern __thread struct thread *pcurthread; + +static __inline struct thread * +__curthread(void) +{ + + return (pcurthread); +} +#define curthread (__curthread()) + +#else /* !lint || defined(__GNUCLIKE_ASM) && defined(__GNUCLIKE___TYPEOF) */ + +#error "this file needs to be ported to your compiler" + +#endif /* lint, etc. */ + +#endif /* _KERNEL */ + +#endif /* !_MACHINE_PCPU_H_ */ Added: user/kmacy/releng_8_rump/lib/libunet/include/machine ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/kmacy/releng_8_rump/lib/libunet/include/machine Sun Jan 24 09:02:38 2010 (r202912) @@ -0,0 +1 @@ +link amd64/include \ No newline at end of file Added: user/kmacy/releng_8_rump/lib/libunet/include/sys/pcpu.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/kmacy/releng_8_rump/lib/libunet/include/sys/pcpu.h Sun Jan 24 09:02:38 2010 (r202912) @@ -0,0 +1,213 @@ +/*- + * Copyright (c) 2001 Wind River Systems, Inc. + * All rights reserved. + * Written by: John Baldwin + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_PCPU_H_ +#define _SYS_PCPU_H_ + +#ifdef LOCORE +#error "no assembler-serviceable parts inside" +#endif + +#include +#include +#include +#include + +struct pcb; +struct thread; + +/* + * Define a set for pcpu data. + * + * We don't use SET_DECLARE because it defines the set as 'a' when we + * want 'aw'. GCC considers uninitialized data in a seperate section + * writable and there is no generic zero initializer that works for + * structs and scalars. + */ +extern uintptr_t *__start_set_pcpu; +extern uintptr_t *__stop_set_pcpu; + +__asm__( +#if defined(__arm__) + ".section set_pcpu, \"aw\", %progbits\n" +#else + ".section set_pcpu, \"aw\", @progbits\n" +#endif + "\t.p2align " __XSTRING(CACHE_LINE_SHIFT) "\n" + "\t.previous"); + +/* + * Array of dynamic pcpu base offsets. Indexed by id. + */ +extern uintptr_t dpcpu_off[]; + +/* + * Convenience defines. + */ +#define DPCPU_START (uintptr_t)&__start_set_pcpu +#define DPCPU_STOP (uintptr_t)&__stop_set_pcpu +#define DPCPU_BYTES (DPCPU_STOP - DPCPU_START) +#define DPCPU_MODMIN 2048 +#define DPCPU_SIZE roundup2(DPCPU_BYTES, PAGE_SIZE) +#define DPCPU_MODSIZE (DPCPU_SIZE - (DPCPU_BYTES - DPCPU_MODMIN)) + +/* + * Declaration and definition. + */ +#define DPCPU_NAME(n) pcpu_entry_##n +#define DPCPU_DECLARE(t, n) extern t DPCPU_NAME(n) +#define DPCPU_DEFINE(t, n) t DPCPU_NAME(n) __section("set_pcpu") __used + +/* + * Accessors with a given base. + */ +#define _DPCPU_PTR(b, n) \ + (__typeof(DPCPU_NAME(n))*)((b) + (uintptr_t)&DPCPU_NAME(n)) +#define _DPCPU_GET(b, n) (*_DPCPU_PTR(b, n)) +#define _DPCPU_SET(b, n, v) (*_DPCPU_PTR(b, n) = v) + +/* + * Accessors for the current cpu. + */ +#define DPCPU_PTR(n) _DPCPU_PTR(PCPU_GET(dynamic), n) +#define DPCPU_GET(n) (*DPCPU_PTR(n)) +#define DPCPU_SET(n, v) (*DPCPU_PTR(n) = v) + +/* + * Accessors for remote cpus. + */ +#define DPCPU_ID_PTR(i, n) _DPCPU_PTR(dpcpu_off[(i)], n) +#define DPCPU_ID_GET(i, n) (*DPCPU_ID_PTR(i, n)) +#define DPCPU_ID_SET(i, n, v) (*DPCPU_ID_PTR(i, n) = v) + +/* + * XXXUPS remove as soon as we have per cpu variable + * linker sets and can define rm_queue in _rm_lock.h +*/ +struct rm_queue { + struct rm_queue* volatile rmq_next; + struct rm_queue* volatile rmq_prev; +}; + +#define PCPU_NAME_LEN (sizeof("CPU ") + sizeof(__XSTRING(MAXCPU) + 1)) + + +/* + * This structure maps out the global data that needs to be kept on a + * per-cpu basis. The members are accessed via the PCPU_GET/SET/PTR + * macros defined in . Machine dependent fields are + * defined in the PCPU_MD_FIELDS macro defined in . + */ +struct pcpu { + struct thread *pc_curthread; /* Current thread */ + struct thread *pc_idlethread; /* Idle thread */ + struct thread *pc_fpcurthread; /* Fp state owner */ + struct thread *pc_deadthread; /* Zombie thread or NULL */ + struct pcb *pc_curpcb; /* Current pcb */ + uint64_t pc_switchtime; + int pc_switchticks; + u_int pc_cpuid; /* This cpu number */ + cpumask_t pc_cpumask; /* This cpu mask */ + cpumask_t pc_other_cpus; /* Mask of all other cpus */ + SLIST_ENTRY(pcpu) pc_allcpu; + struct lock_list_entry *pc_spinlocks; +#ifdef KTR + char pc_name[PCPU_NAME_LEN]; /* String name for KTR. */ +#endif + struct vmmeter pc_cnt; /* VM stats counters */ + long pc_cp_time[CPUSTATES]; /* statclock ticks */ + struct device *pc_device; + void *pc_netisr; /* netisr SWI cookie. */ + + /* + * Stuff for read mostly lock + * + * XXXUPS remove as soon as we have per cpu variable + * linker sets. + */ + struct rm_queue pc_rm_queue; + + /* + * Dynamic per-cpu data area. + */ + uintptr_t pc_dynamic; + + /* + * Keep MD fields last, so that CPU-specific variations on a + * single architecture don't result in offset variations of + * the machine-independent fields of the pcpu. Even though + * the pcpu structure is private to the kernel, some ports + * (e.g. lsof, part of gtop) define _KERNEL and include this + * header. While strictly speaking this is wrong, there's no + * reason not to keep the offsets of the MI fields contants. + * If only to make kernel debugging easier... + */ + PCPU_MD_FIELDS; +} __aligned(128); + +#ifdef _KERNEL + +SLIST_HEAD(cpuhead, pcpu); + +extern struct cpuhead cpuhead; + +#define curcpu 0 +#define curproc (curthread->td_proc) +#ifndef curthread +#define curthread PCPU_GET(curthread) +#endif +#define curvidata PCPU_GET(vidata) + +/* + * Machine dependent callouts. cpu_pcpu_init() is responsible for + * initializing machine dependent fields of struct pcpu, and + * db_show_mdpcpu() is responsible for handling machine dependent + * fields for the DDB 'show pcpu' command. + */ + +extern struct pcpu *cpuid_to_pcpu[MAXCPU]; + + +void cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size); +void db_show_mdpcpu(struct pcpu *pcpu); + +void pcpu_destroy(struct pcpu *pcpu); +struct pcpu *pcpu_find(u_int cpuid); +void pcpu_init(struct pcpu *pcpu, int cpuid, size_t size); +void *dpcpu_alloc(int size); +void dpcpu_copy(void *s, int size); +void dpcpu_free(void *s, int size); +void dpcpu_init(void *dpcpu, int cpuid); + +#endif /* _KERNEL */ + +#endif /* !_SYS_PCPU_H_ */ Modified: user/kmacy/releng_8_rump/lib/libunet/test/init.c ============================================================================== --- user/kmacy/releng_8_rump/lib/libunet/test/init.c Sun Jan 24 08:59:33 2010 (r202911) +++ user/kmacy/releng_8_rump/lib/libunet/test/init.c Sun Jan 24 09:02:38 2010 (r202912) @@ -1,6 +1,7 @@ #include #include #include +#include extern void mi_startup(void); extern void uma_startup(void *, int); @@ -12,13 +13,16 @@ extern int ncallout; int main(void) { + struct pcpu *pc; + /* vm_init bits */ ncallout = 64; + pc = malloc(sizeof(struct pcpu)); + pcpu_init(pc, 0, sizeof(struct pcpu)); kern_timeout_callwheel_alloc(malloc(512*1024)); kern_timeout_callwheel_init(); uma_startup(NULL, 0); - mi_startup(); } Modified: user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_compat.c ============================================================================== --- user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_compat.c Sun Jan 24 08:59:33 2010 (r202911) +++ user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_compat.c Sun Jan 24 09:02:38 2010 (r202912) @@ -98,6 +98,25 @@ getmicrotime(struct timeval *tvp) gettimeofday(&tv, NULL); } +__thread struct thread *pcurthread; + +struct pthread_start_args +{ + struct thread *psa_td; + void (*psa_start_routine)(void *); + void *psa_arg; +}; + +static void * +pthread_start_routine(void *arg) +{ + struct pthread_start_args *psa = arg; + + pcurthread = psa->psa_td; + psa->psa_start_routine(psa->psa_arg); + free(psa); +} + int kproc_kthread_add(void (*start_routine)(void *), void *arg, struct proc **p, struct thread **td, @@ -107,11 +126,16 @@ kproc_kthread_add(void (*start_routine)( int error; pthread_t thread; pthread_attr_t attr; + struct pthread_start_args *psa; *td = malloc(sizeof(struct thread)); - pthread_attr_init(&attr); + psa = malloc(sizeof(struct pthread_start_args)); + psa->psa_start_routine = start_routine; + psa->psa_arg = arg; + psa->psa_td = *td; - error = pthread_create(&thread, &attr, start_routine, arg); + pthread_attr_init(&attr); + error = pthread_create(&thread, &attr, pthread_start_routine, psa); return (error); } Modified: user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_glue.c ============================================================================== --- user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_glue.c Sun Jan 24 08:59:33 2010 (r202911) +++ user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_glue.c Sun Jan 24 09:02:38 2010 (r202912) @@ -23,6 +23,9 @@ #include #include +int bootverbose; +struct prison prison0; + SYSCTL_NODE(, 0, sysctl, CTLFLAG_RW, 0, "Sysctl internal magic"); @@ -755,3 +758,9 @@ knlist_init_mtx(struct knlist *knl, stru { } + +void +module_register_init(void *arg) +{ + printf("skipped module registration"); +} Modified: user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_kern_intr.c ============================================================================== --- user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_kern_intr.c Sun Jan 24 08:59:33 2010 (r202911) +++ user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_kern_intr.c Sun Jan 24 09:02:38 2010 (r202912) @@ -850,6 +850,7 @@ swi_add(struct intr_event **eventp, cons (pri * RQ_PPQ) + PI_SOFT, flags, cookiep); if (error) return (error); +#if 0 if (pri == SWI_CLOCK) { struct proc *p; p = ie->ie_thread->it_thread->td_proc; @@ -857,6 +858,7 @@ swi_add(struct intr_event **eventp, cons p->p_flag |= P_NOLOAD; PROC_UNLOCK(p); } +#endif return (0); } Modified: user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_kern_synch.c ============================================================================== --- user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_kern_synch.c Sun Jan 24 08:59:33 2010 (r202911) +++ user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_kern_synch.c Sun Jan 24 09:02:38 2010 (r202912) @@ -40,7 +40,7 @@ typedef struct sleep_entry { } *sleep_entry_t; static void synch_setup(void *dummy); -SYSINIT(synch_setup, SI_SUB_KICK_SCHEDULER, SI_ORDER_FIRST, synch_setup, +SYSINIT(synch_setup, SI_SUB_INTR, SI_ORDER_FIRST, synch_setup, NULL); static struct se_head *se_active; From owner-svn-src-user@FreeBSD.ORG Sun Jan 24 09:05:44 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 57829106566B; Sun, 24 Jan 2010 09:05:44 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4704D8FC13; Sun, 24 Jan 2010 09:05:44 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0O95iUw078619; Sun, 24 Jan 2010 09:05:44 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0O95iUK078617; Sun, 24 Jan 2010 09:05:44 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <201001240905.o0O95iUK078617@svn.freebsd.org> From: Kip Macy Date: Sun, 24 Jan 2010 09:05:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r202913 - user/kmacy/releng_8_rump/lib/libunet/unet_sys X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Jan 2010 09:05:44 -0000 Author: kmacy Date: Sun Jan 24 09:05:43 2010 New Revision: 202913 URL: http://svn.freebsd.org/changeset/base/202913 Log: remove incorrect panic Modified: user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_init_main.c Modified: user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_init_main.c ============================================================================== --- user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_init_main.c Sun Jan 24 09:02:38 2010 (r202912) +++ user/kmacy/releng_8_rump/lib/libunet/unet_sys/unet_init_main.c Sun Jan 24 09:05:43 2010 (r202913) @@ -280,6 +280,4 @@ restart: } } - panic("Shouldn't get here!"); - /* NOTREACHED*/ } From owner-svn-src-user@FreeBSD.ORG Sun Jan 24 20:35:55 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DFB8B1065672; Sun, 24 Jan 2010 20:35:55 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id CDCBD8FC16; Sun, 24 Jan 2010 20:35:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0OKZtlZ036505; Sun, 24 Jan 2010 20:35:55 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0OKZtko036496; Sun, 24 Jan 2010 20:35:55 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <201001242035.o0OKZtko036496@svn.freebsd.org> From: Luigi Rizzo Date: Sun, 24 Jan 2010 20:35:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r202948 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Jan 2010 20:35:56 -0000 Author: luigi Date: Sun Jan 24 20:35:55 2010 New Revision: 202948 URL: http://svn.freebsd.org/changeset/base/202948 Log: more testing support Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/Makefile user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_fifo.c user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_rr.c user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_wf2q.c user/luigi/ipfw3-head/sys/netinet/ipfw/dn_test.h user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dn_private.h user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c user/luigi/ipfw3-head/sys/netinet/ipfw/test_dn_sched.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/Makefile ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/Makefile Sun Jan 24 20:15:59 2010 (r202947) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/Makefile Sun Jan 24 20:35:55 2010 (r202948) @@ -2,13 +2,16 @@ SCHED_SRCS = test_dn_sched.c SCHED_SRCS += dn_sched_fifo.c +SCHED_SRCS += dn_sched_wf2q.c +SCHED_SRCS += dn_sched_rr.c +SCHED_SRCS += dn_heap.c SCHED_OBJS=$(SCHED_SRCS:.c=.o) HEAP_SRCS = dn_heap.c test_dn_heap.c HEAP_OBJS=$(HEAP_SRCS:.c=.o) -CFLAGS = -I../../ -Wall -Werror -O2 +CFLAGS = -I. -Wall -Werror -O2 -DIPFW TARGETS= test_heap test_sched all: $(TARGETS) Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_fifo.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_fifo.c Sun Jan 24 20:15:59 2010 (r202947) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_fifo.c Sun Jan 24 20:35:55 2010 (r202948) @@ -40,7 +40,7 @@ #include #include #else -#include "dn_test.h" +#include #endif /* Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_rr.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_rr.c Sun Jan 24 20:15:59 2010 (r202947) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_rr.c Sun Jan 24 20:35:55 2010 (r202948) @@ -40,7 +40,7 @@ #include #include #else -#include "dn_test.h" +#include #endif #define DN_SCHED_RR 3 // XXX Where? @@ -198,7 +198,7 @@ static int rr_config(struct new_schk *_schk) { struct rr_schk *schk = (struct rr_schk *)(_schk + 1); - printf("%s called\n", __FUNCTION__); + D("called"); schk->min_q = 1; schk->max_q = 1000; @@ -212,7 +212,7 @@ rr_new_sched(struct new_sch_inst *_si) { struct rr_si *si = (struct rr_si *)(_si + 1); - printf("%s called\n", __FUNCTION__); + D("called"); si->head = si->tail = NULL; return 0; @@ -221,7 +221,7 @@ rr_new_sched(struct new_sch_inst *_si) static int rr_free_sched(struct new_sch_inst *_si) { - printf("%s called\n", __FUNCTION__); + D("called"); /* Nothing to do? */ return 0; } @@ -241,7 +241,7 @@ rr_new_queue(struct new_queue *_q) struct rr_queue *q = (struct rr_queue *)_q; struct rr_schk *schk = (struct rr_schk *)(_q->_si->sched + 1); - printf("%s called, schk->quantum=%d\n", __FUNCTION__, schk->q_bytes); + D("called, schk->quantum=%d", schk->q_bytes); _q->ni.oid.subtype = DN_SCHED_RR; q->quantum = _q->fs->fs.par[0] * schk->q_bytes; @@ -260,7 +260,7 @@ rr_free_queue(struct new_queue *_q) { struct rr_queue *q = (struct rr_queue *)_q; - printf("%s called\n", __FUNCTION__); + D("called"); if (q->status == 1) { struct rr_si *si = (struct rr_si *)(_q->_si + 1); remove_queue_q(q, si); Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_wf2q.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_wf2q.c Sun Jan 24 20:15:59 2010 (r202947) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_wf2q.c Sun Jan 24 20:35:55 2010 (r202948) @@ -41,7 +41,7 @@ #include #include #else -#include "dn_test.h" +#include #endif #ifndef MAX64 Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/dn_test.h ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/dn_test.h Sun Jan 24 20:15:59 2010 (r202947) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/dn_test.h Sun Jan 24 20:35:55 2010 (r202948) @@ -1,20 +1,55 @@ /* - * Header for testing kernel stuff in userland + * userspace compatibility code for dummynet schedulers` */ #ifndef _DN_TEST_H #define _DN_TEST_H +#include #include #include #include /* bzero */ +#include /* strcmp */ #include #include #include #include -#define MALLOC_DECLARE(x) -#define KASSERT(x, y) do { if (!(x)) printf y ; exit(0); } while (0) -struct ipfw_flow_id { +#define ND(fmt, args...) do {} while (0) +#define D1(fmt, args...) do {} while (0) +#define D(fmt, args...) fprintf(stderr, "%-10s " fmt "\n", \ + __FUNCTION__, ## args) +#define DX(lev, fmt, args...) do { \ + if (debug > lev) D(fmt, ## args); } while (0) + +#define offsetof(t,m) (int)((&((t *)0L)->m)) + +/* prevent include of other system headers */ +#define _NETINET_IP_VAR_H_ /* ip_fw_args */ +#define _IPFW2_H +#define _SYS_MBUF_H_ + +enum { + DN_QUEUE, +}; + +enum { + DN_SCHED_FIFO, + DN_SCHED_WF2QP, +}; + +struct dn_id { + int type, subtype, len, id; +}; +struct new_fs { + int par[1]; +}; +struct new_sch { +}; +struct dn_flow { + struct dn_id oid; + int length, len_bytes, drops; +}; +struct dn_link { }; struct ip_fw_args { @@ -25,8 +60,16 @@ struct mbuf { int len; } m_pkthdr; struct mbuf *m_nextpkt; - int flow_id; + int flow_id; /* for testing, index of a flow */ + int flowset_id; /* for testing, index of a flowset */ + void *cfg; /* config args */ }; + +#define MALLOC_DECLARE(x) +#define KASSERT(x, y) do { if (!(x)) printf y ; exit(0); } while (0) +struct ipfw_flow_id { +}; + typedef void * module_t; struct _md_t { const char *name; @@ -35,12 +78,38 @@ struct _md_t { }; typedef struct _md_t moduledata_t; #define DECLARE_MODULE(name, b, c, d) \ - moduledata_t *_g_##name = & name##_mod + moduledata_t *_g_##name = & b #define MODULE_DEPEND(a, b, c, d, e) -#include -#include -#include -#include +#ifdef IPFW +#include +#include +#include +#else +struct new_queue { + struct new_fsk *fs; /* parent flowset. */ + struct new_sch_inst *_si; /* parent sched instance. */ +}; +struct new_schk { +}; +struct new_fsk { + struct new_fs fs; + struct new_schk *sched; +}; +struct new_sch_inst { + struct new_schk *sched; +}; +struct dn_alg { + int type; + const char *name; + void *enqueue, *dequeue; + int q_datalen, si_datalen, schk_datalen; + int (*config)(struct new_schk *); + int (*new_sched)(struct new_sch_inst *); + int (*new_fsk)(struct new_fsk *); + int (*new_queue)(struct new_queue *q); +}; + +#endif #endif /* _DN_TEST_H */ Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dn_private.h ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dn_private.h Sun Jan 24 20:15:59 2010 (r202947) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dn_private.h Sun Jan 24 20:35:55 2010 (r202948) @@ -31,6 +31,20 @@ * internal dummynet APIs. */ +/* debugging support + * use ND() to remove debugging, D() to print a line, + * DX(level, ...) to print above a certain level + * If you redefine D() you are expected to redefine all. + */ +#ifndef D +#define ND(fmt, args...) do {} while (0) +#define D1(fmt, args...) do {} while (0) +#define D(fmt, args...) printf("%-10s " fmt "\n", \ + __FUNCTION__, ## args) +#define DX(lev, fmt, args...) do { \ + if (dn_cfg.debug > lev) D(fmt, ## args); } while (0) +#endif + MALLOC_DECLARE(M_DUMMYNET); #ifndef FREE_PKT Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c Sun Jan 24 20:15:59 2010 (r202947) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c Sun Jan 24 20:35:55 2010 (r202948) @@ -34,11 +34,6 @@ __FBSDID("$FreeBSD$"); #include "opt_inet6.h" -/* debug support */ -#define ND(fmt, args...) do {} while (0) -#define D(fmt, args...) printf("%s %d: " fmt "\n", \ - __FUNCTION__ , __LINE__ , ## args) - #include #include #include Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/test_dn_sched.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/test_dn_sched.c Sun Jan 24 20:15:59 2010 (r202947) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/test_dn_sched.c Sun Jan 24 20:35:55 2010 (r202948) @@ -3,12 +3,6 @@ */ #include "dn_test.h" -#include -#include -#include -#include - -int io_pkt_drop; void m_freem(struct mbuf *m) @@ -76,6 +70,17 @@ drop: q->ni.drops++; return 1; } +int +ipdn_bound_var(int *v, int dflt, int lo, int hi, const char *msg) +{ + if (*v < lo) { + *v = dflt; + } else if (*v > hi) { + *v = hi; + } + return *v; +} + #ifndef NO_MAIN int main(int argc, char *argv[]) From owner-svn-src-user@FreeBSD.ORG Sun Jan 24 22:33:48 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3ED061065679; Sun, 24 Jan 2010 22:33:48 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2DF838FC08; Sun, 24 Jan 2010 22:33:48 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0OMXm20062638; Sun, 24 Jan 2010 22:33:48 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0OMXm15062636; Sun, 24 Jan 2010 22:33:48 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <201001242233.o0OMXm15062636@svn.freebsd.org> From: Luigi Rizzo Date: Sun, 24 Jan 2010 22:33:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r202953 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Jan 2010 22:33:48 -0000 Author: luigi Date: Sun Jan 24 22:33:47 2010 New Revision: 202953 URL: http://svn.freebsd.org/changeset/base/202953 Log: indentation fix Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_rr.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_rr.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_rr.c Sun Jan 24 22:29:35 2010 (r202952) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_rr.c Sun Jan 24 22:33:47 2010 (r202953) @@ -119,8 +119,8 @@ remove_queue_q(struct rr_queue *q, struc prev->qnext = q->qnext; if (q == si->tail) si->tail = prev; - q->status = 0; -} + q->status = 0; + } prev = prev->qnext; } } From owner-svn-src-user@FreeBSD.ORG Tue Jan 26 16:47:34 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ACEA31065692; Tue, 26 Jan 2010 16:47:34 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 841A18FC1F; Tue, 26 Jan 2010 16:47:34 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0QGlYB2046250; Tue, 26 Jan 2010 16:47:34 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0QGlYli046248; Tue, 26 Jan 2010 16:47:34 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <201001261647.o0QGlYli046248@svn.freebsd.org> From: Luigi Rizzo Date: Tue, 26 Jan 2010 16:47:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r203035 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jan 2010 16:47:34 -0000 Author: luigi Date: Tue Jan 26 16:47:34 2010 New Revision: 203035 URL: http://svn.freebsd.org/changeset/base/203035 Log: fix two bugs in the scheduler Submitted by: Riccardo Panicucci Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_wf2q.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_wf2q.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_wf2q.c Tue Jan 26 16:18:45 2010 (r203034) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched_wf2q.c Tue Jan 26 16:47:34 2010 (r203035) @@ -182,7 +182,20 @@ wf2qp_dequeue(struct new_sch_inst *_si) idle_check(si, 1, 0); /* drain something from the idle heap */ /* make sure at least one element is eligible, bumping V - * and moving entries that have become eligible + * and moving entries that have become eligible. + * We need to repeat the first part twice, before and + * after extracting the candidate, or enqueue() will + * find the data structure in a wrong state. + */ + pkt = NULL; + for(;;) { + /* + * Compute V = max(V, min(S_i)). Remember that all elements + * in sch have by definition S_i <= V so if sch is not empty, + * V is surely the max and we must not update it. Conversely, + * if sch is empty we only need to look at neh. + * We don't need to move the queues, as it will be done at the + * next enqueue */ if (sch->elements == 0 && neh->elements > 0) { si->V = MAX64(si->V, HEAP_TOP(neh)->key); @@ -190,10 +203,12 @@ wf2qp_dequeue(struct new_sch_inst *_si) while (neh->elements > 0 && DN_KEY_LEQ(HEAP_TOP(neh)->key, si->V)) { q = HEAP_TOP(neh)->object; - alg_fq = (struct wf2qp_queue *)q; + alg_fq = (struct wf2qp_queue *)(q + 1); heap_extract(neh, NULL); heap_insert(sch, alg_fq->F, q); } + if (pkt) /* pkt found in previous iteration */ + break; /* ok we have at least one eligible pkt */ q = HEAP_TOP(sch)->object; alg_fq = (struct wf2qp_queue *)(q + 1); @@ -213,18 +228,7 @@ wf2qp_dequeue(struct new_sch_inst *_si) heap_insert(neh, alg_fq->S, q); } } - - /* - * Now compute V = max(V, min(S_i)). Remember that all elements - * in sch have by definition S_i <= V so if sch is not empty, - * V is surely the max and we must not update it. Conversely, - * if sch is empty we only need to look at neh. - * We don't need to move the queues, as it will be done at the - * next enqueue - */ - if (sch->elements == 0 && neh->elements > 0) { - si->V = MAX64(si->V, HEAP_TOP(neh)->key); - } + } return pkt; } From owner-svn-src-user@FreeBSD.ORG Wed Jan 27 14:17:33 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 668791065672; Wed, 27 Jan 2010 14:17:33 +0000 (UTC) (envelope-from des@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5694F8FC16; Wed, 27 Jan 2010 14:17:33 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0REHXG9037278; Wed, 27 Jan 2010 14:17:33 GMT (envelope-from des@svn.freebsd.org) Received: (from des@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0REHXlu037276; Wed, 27 Jan 2010 14:17:33 GMT (envelope-from des@svn.freebsd.org) Message-Id: <201001271417.o0REHXlu037276@svn.freebsd.org> From: Dag-Erling Smorgrav Date: Wed, 27 Jan 2010 14:17:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r203069 - user/des/fmerge X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jan 2010 14:17:33 -0000 Author: des Date: Wed Jan 27 14:17:33 2010 New Revision: 203069 URL: http://svn.freebsd.org/changeset/base/203069 Log: When merging multiple ranges, merge them in chronological order, not reverse chronological. Modified: user/des/fmerge/fmerge.pl Modified: user/des/fmerge/fmerge.pl ============================================================================== --- user/des/fmerge/fmerge.pl Wed Jan 27 11:54:42 2010 (r203068) +++ user/des/fmerge/fmerge.pl Wed Jan 27 14:17:33 2010 (r203069) @@ -178,9 +178,9 @@ sub revs2ranges() { next; } else { if ($revs{$m} == +1) { - push(@ranges, [ $m - 1, $n ]); + unshift(@ranges, [ $m - 1, $n ]); } elsif ($revs{$m} == -1) { - push(@ranges, [ $n, $m - 1 ]); + unshift(@ranges, [ $n, $m - 1 ]); } $m = $n = $i; } From owner-svn-src-user@FreeBSD.ORG Fri Jan 29 06:39:58 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0440E1065679; Fri, 29 Jan 2010 06:39:58 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E5F7C8FC1B; Fri, 29 Jan 2010 06:39:57 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0T6dvqa080144; Fri, 29 Jan 2010 06:39:57 GMT (envelope-from edwin@svn.freebsd.org) Received: (from edwin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0T6dvj4080133; Fri, 29 Jan 2010 06:39:57 GMT (envelope-from edwin@svn.freebsd.org) Message-Id: <201001290639.o0T6dvj4080133@svn.freebsd.org> From: Edwin Groothuis Date: Fri, 29 Jan 2010 06:39:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r203154 - user/edwin/calendar X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jan 2010 06:39:58 -0000 Author: edwin Date: Fri Jan 29 06:39:57 2010 New Revision: 203154 URL: http://svn.freebsd.org/changeset/base/203154 Log: Support for sun-position calculation: solstice and equinox Added: user/edwin/calendar/chinesecalendar.txt user/edwin/calendar/cny.c user/edwin/calendar/sunpos.c user/edwin/calendar/sunpos.txt Modified: user/edwin/calendar/Makefile user/edwin/calendar/calendar.h user/edwin/calendar/io.c user/edwin/calendar/ostern.c user/edwin/calendar/parsedata.c user/edwin/calendar/paskha.c Modified: user/edwin/calendar/Makefile ============================================================================== --- user/edwin/calendar/Makefile Fri Jan 29 05:44:20 2010 (r203153) +++ user/edwin/calendar/Makefile Fri Jan 29 06:39:57 2010 (r203154) @@ -5,7 +5,7 @@ CFLAGS= -pipe -g -std=gnu99 -fstack-pr PROG= calendar SRCS= calendar.c locale.c events.c dates.c parsedata.c io.c day.c \ - ostern.c paskha.c pom.c + ostern.c paskha.c pom.c sunpos.c LDADD= -lm INTER= de_AT.ISO_8859-15 de_DE.ISO8859-1 fr_FR.ISO8859-1 \ hr_HR.ISO8859-2 hu_HU.ISO8859-2 ru_RU.KOI8-R uk_UA.KOI8-U @@ -13,9 +13,6 @@ DE_LINKS= de_DE.ISO8859-15 FR_LINKS= fr_FR.ISO8859-15 TEXTMODE?= 444 -pom: pom.c - gcc -g -Wall -o pom pom.c -lm - beforeinstall: ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${TEXTMODE} \ ${.CURDIR}/calendars/calendar.* ${DESTDIR}${SHAREDIR}/calendar Modified: user/edwin/calendar/calendar.h ============================================================================== --- user/edwin/calendar/calendar.h Fri Jan 29 05:44:20 2010 (r203153) +++ user/edwin/calendar/calendar.h Fri Jan 29 06:39:57 2010 (r203154) @@ -48,31 +48,40 @@ extern time_t t1, t2; extern const char *calendarFile; extern int yrdays; extern struct fixs neaster, npaskha, ncny, nfullmoon, nnewmoon; +extern struct fixs nmarequinox, nsepequinox, njunsolstice, ndecsolstice; #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) /* Flags to determine the returned values by determinestyle() in parsedata.c */ -#define F_NONE 0x0000 -#define F_MONTH 0x0001 -#define F_DAYOFWEEK 0x0002 -#define F_DAYOFMONTH 0x0004 -#define F_MODIFIERINDEX 0x0008 -#define F_MODIFIEROFFSET 0x0010 -#define F_SPECIALDAY 0x0020 -#define F_ALLMONTH 0x0040 -#define F_ALLDAY 0x0080 -#define F_VARIABLE 0x0100 -#define F_EASTER 0x0200 -#define F_CNY 0x0400 -#define F_PASKHA 0x0800 -#define F_NEWMOON 0x1000 -#define F_FULLMOON 0x2000 +#define F_NONE 0x00000 +#define F_MONTH 0x00001 +#define F_DAYOFWEEK 0x00002 +#define F_DAYOFMONTH 0x00004 +#define F_MODIFIERINDEX 0x00008 +#define F_MODIFIEROFFSET 0x00010 +#define F_SPECIALDAY 0x00020 +#define F_ALLMONTH 0x00040 +#define F_ALLDAY 0x00080 +#define F_VARIABLE 0x00100 +#define F_EASTER 0x00200 +#define F_CNY 0x00400 +#define F_PASKHA 0x00800 +#define F_NEWMOON 0x01000 +#define F_FULLMOON 0x02000 +#define F_MAREQUINOX 0x04000 +#define F_SEPEQUINOX 0x08000 +#define F_JUNSOLSTICE 0x10000 +#define F_DECSOLSTICE 0x20000 #define STRING_EASTER "Easter" #define STRING_PASKHA "Paskha" #define STRING_CNY "ChineseNewYear" #define STRING_NEWMOON "NewMoon" #define STRING_FULLMOON "FullMoon" +#define STRING_MAREQUINOX "MarEquinox" +#define STRING_SEPEQUINOX "SepEquinox" +#define STRING_JUNSOLSTICE "JunSolstice" +#define STRING_DECSOLSTICE "DecSolstice" extern int debug; /* show parsing of the input */ extern int f_dayAfter; /* days after current date */ @@ -152,3 +161,5 @@ void addtodate(struct event *e, int year #define MAXMOONS 15 void pom(int year, int *fms, int *nms); +/* sunpos.c */ +void equinoxsolstice(int year, double UTCoffset, int *equinoxdays, int *solsticedays); Added: user/edwin/calendar/chinesecalendar.txt ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/edwin/calendar/chinesecalendar.txt Fri Jan 29 06:39:57 2010 (r203154) @@ -0,0 +1,387 @@ +http://www.webexhibits.org/calendars/calendar-chinese.html +Title: The Chinese Calendar | Calendar +Important stuff: Prefixed with | + + + The Chinese Calendar + Dragon + + Chinese New Year Celebrations + + Chinese New Year parades have their origins in the California Gold Rush, + when immigrants sought to share their culture. Today, New Year's parades + take place around the globe. + + Chinese New Year is the main holiday of the year for more than one quarter + of the world's population. Although the People's Republic of China uses + the Gregorian calendar for civil purposes, a special Chinese calendar is + used for determining festivals. Various Chinese communities around the + world also use this calendar. + + The beginnings of the Chinese calendar can be traced back to the 14th + century B.C.E. Legend has it that the Emperor Huangdi invented the + calendar in 2637 B.C.E. + + The Chinese calendar is based on exact astronomical observations of the + longitude of the sun and the phases of the moon. This means that + principles of modern science have had an impact on the Chinese calendar. + + * What Does the Chinese Year Look Like? + * What Years Are Leap Years? + * How Does One Count Years? + * What Is the Current Year in the Chinese Calendar? + * What about the year 2033? + * When did the calendar really start? + * What was the early Chinese calendar? + * Details of early calendars + * When were foreign calendars introduced? + + What Does the Chinese Year Look Like? + + The Chinese calendar - like the Hebrew - is a combined solar/lunar + calendar in that it strives to have its years coincide with the tropical + year and its months coincide with the synodic months. It is not surprising + that a few similarities exist between the Chinese and the Hebrew calendar: + + * An ordinary year has 12 months, a leap year has 13 months. + * An ordinary year has 353, 354, or 355 days, a leap year has 383, 384, + or 385 days. + +| When determining what a Chinese year looks like, one must make a number of +| astronomical calculations: +| +| First, determine the dates for the new moons. Here, a new moon is the +| completely "black" moon (that is, when the moon is in conjunction with the +| sun), not the first visible crescent used in the Islamic and Hebrew +| calendars. The date of a new moon is the first day of a new month. +| +| Second, determine the dates when the sun's longitude is a multiple of 30 +| degrees. (The sun's longitude is 0 at Vernal Equinox, 90 at Summer +| Solstice, 180 at Autumnal Equinox, and 270 at Winter Solstice.) These +| dates are called the Principal Terms and are used to determine the number +| of each month: + + * Principal Term 1 occurs when the sun's longitude is 330 degrees. + * Principal Term 2 occurs when the sun's longitude is 0 degrees. + * Principal Term 3 occurs when the sun's longitude is 30 degrees. (etc.) + * Principal Term 11 occurs when the sun's longitude is 270 degrees. + * Principal Term 12 occurs when the sun's longitude is 300 degrees. + + Each month carries the number of the Principal Term that occurs in that + month. + + In rare cases, a month may contain two Principal Terms; in this case the + months numbers may have to be shifted. Principal Term 11 (Winter Solstice) + must always fall in the 11th month. + +| All the astronomical calculations are carried out for the meridian 120 +| degrees east of Greenwich. This roughly corresponds to the east coast of +| China. + + Some variations in these rules are seen in various Chinese communities. + + What Years Are Leap Years? + + Leap years have 13 months. To determine if a year is a leap year, + calculate the number of new moons between the 11th month in one year + (i.e., the month containing the Winter Solstice) and the 11th month in the + following year. If there are 13 new moons from the start of the 11th month + in the first year to the start of the 11th month in the second year, a + leap month must be inserted. + + In leap years, at least one month does not contain a Principal Term. The + first such month is the leap month. It carries the same number as the + previous month, with the additional note that it is the leap month. + + How Does One Count Years? + + Unlike most other calendars, the Chinese calendar does not count years in + an infinite sequence. Instead years have names that are repeated every 60 + years. + + (Historically, years used to be counted since the accession of an emperor, + but this was abolished after the 1911 revolution.) + + Within each 60-year cycle, each year is assigned name consisting of two + components: + + The first component is a Celestial Stemm. These words have no English + equivalent: + + 1 jia 6 ji + 2 yi 7 geng + 3 bing 8 xin + 4 ding 9 ren + 5 wu 10 gui + + The second component is a Terrestrial Branch. The names of the + corresponding animals in the zodiac cycle of 12 animals are given in + parentheses. + + 1 zi (rat) 7 wu (horse) + 2 chou (ox) 8 wei (sheep) + 3 yin (tiger) 9 shen (monkey) + 4 mao (hare, rabbit) 10 you (rooster) + 5 chen (dragon) 11 xu (dog) + 6 si (snake) 12 hai (pig) + + Each of the two components is used sequentially. Thus, the 1st year of the + 60-year cycle becomes jia-zi, the 2nd year is yi-chou, the 3rd year is + bing-yin, etc. When we reach the end of a component, we start from the + beginning: The 10th year is gui-you, the 11th year is jia-xu (restarting + the Celestial Stem), the 12th year is yi-hai, and the 13th year is bing-zi + (restarting the Terrestrial Branch). Finally, the 60th year becomes + gui-hai. + + This way of naming years within a 60-year cycle goes back approximately + 2000 years. A similar naming of days and months has fallen into disuse, + but the date name is still listed in calendars. + + It is customary to number the 60-year cycles since 2637 B.C.E., when the + calendar was supposedly invented. In that year the first 60-year cycle + started. + + What Is the Current Year in the Chinese Calendar? + +| The current 60-year cycle started on 2 Feb 1984. That date bears the name +| bing-yin in the 60-day cycle, and the first month of that first year bears +| the name gui-chou in the 60-month cycle. + + This means that the year wu-yin, the 15th year in the 78th cycle, started + on 28 Jan 1998. The 20th year in the 78th cycle, started on 1 Feb 2003. + + The following are dates for Chinese/Lunar New Year's day: + + Chinese year Zodiac animal Gregorian calendar + 4693 Boar January 31, 1995 + 4694 Rat February 19, 1996 + 4695 Ox February 7, 1997 + 4696 Tiger January 28, 1998 + 4697 Hare/Rabbit February 16, 1999 + 4698 Dragon February 5, 2000 + 4699 Snake January 24, 2001 + 4700 Horse February 12, 2002 + 4701 Ram/Sheep February 1, 2003 + 4702 Monkey January 22, 2004 + 4703 Rooster February 9, 2005 + 4704 Dog January 29, 2006 + 4705 Boar February 18, 2007 + 4706 Rat February 7, 2008 + 4707 Ox January 26, 2009 + 4708 Tiger February 10, 2010 + 4709 Hare/Rabbit February 3, 2011 + 4710 Dragon January 23, 2012 + 4711 Snake February 10, 2013 + 4712 Horse January 31, 2014 + 4713 Ram/Sheep February 19, 2015 + 4714 Monkey February 9, 2016 + 4715 Rooster January 28, 2017 + 4716 Dog February 16, 2018 + 4717 Boar February 5, 2019 + 4718 Rat January 25, 2020 + + What about the year 2033? + + In the early 1990s, Chinese astronomers discovered that there was an error + in the Chinese calendar for 2033. The traditional calendar claimed that + the leap month would follow the 7th month, while in fact it comes after + the 11th month. It is very unusual that the 11th month has a leap month, + in fact it hasn't happened since the calendar reform in 1645 (before 1645, + all months had the same probability for having a leap month). But many + Chinese astronomers still claim that there will never be a leap month + after the 12th and 1st month. In addition, there will be a leap month + after the 1st month in 2262 (in fact, it should have happened in 1651, but + they got the calculations wrong!) and there will be a leap month after the + 12th month in 3358. Since the Chinese calendar is an astronomical + calendar, predictions require delicate astronomical calculations, so my + computations for 3358 should probably be taken with a grain of salt. + + When did the calendar really start? + + If the Chinese calendar started in 2637 B.C.E., why is the current year 60 + years too late? (e.g., in 1999, the current year was 4697? and not 4637)? + + The Chinese calendar does not use a continuous year count! They used a 60 + year cycle and a system of regional years (starting with each emperor). + Before the 1911 revolution, Sun Yat-sen wanted to establish a republican + alternative to the imperial reign cycles. According to Chinese tradition, + the first year of the Yellow Emperor was 2698 B.C.E., so he introduced a + counting system based on this. Under this system, 2000 is year 4698. An + alternative system is to start with the first historical record of the + 60-day cycle from March 8, 2637 B.C.E. Based on this system, 2000 is year + 4637. + + shang oracle bones + + Two oracle bones from the Shang Dynasty in China (c. 1800 - 1200 BCE) + + Evidence from the Shang oracle bone inscriptions shows that at least by + the 14th century BC the Shang Chinese had established the solar year at + 365 1/4 days and lunation at 29 1/2 days. In the calendar that the Shang + used, the seasons of the year and the phases of the Moon were all + supposedly accounted for. + + What was the Early Chinese calendar? + + In China, the calendar was a sacred document, sponsored and promulgated by + the reigning monarch. For more than two millennia, a Bureau of Astronomy + made astronomical observations, calculated astronomical events such as + eclipses, prepared astrological predictions, and maintained the calendar. + After all, a successful calendar not only served practical needs, but also + confirmed the consonance between Heaven and the imperial court. + + Analysis of surviving astronomical records inscribed on oracle bones + reveals a Chinese lunisolar calendar, with intercalation of lunar months, + dating back to the Shang dynasty of the fourteenth century B.C.E. Various + intercalation schemes were developed for the early calendars, including + the nineteen-year and 76-year lunar phase cycles that came to be known in + the West as the Metonic cycle and Callipic cycle. + + From the earliest records, the beginning of the year occurred at a New + Moon near the winter solstice. The choice of month for beginning the civil + year varied with time and place, however. In the late second century + B.C.E., a calendar reform established the practice, which continues today, + of requiring the winter solstice to occur in month 11. This reform also + introduced the intercalation system in which dates of New Moons are + compared with the 24 solar terms. However, calculations were based on the + mean motions resulting from the cyclic relationships. Inequalities in the + Moon's motions were incorporated as early as the seventh century C.E., but + the Sun's mean longitude was used for calculating the solar terms until + 1644. + + Years were counted from a succession of eras established by reigning + emperors. Although the accession of an emperor would mark a new era, an + emperor might also declare a new era at various times within his reign. + The introduction of a new era was an attempt to reestablish a broken + connection between Heaven and Earth, as personified by the emperor. The + break might be revealed by the death of an emperor, the occurrence of a + natural disaster, or the failure of astronomers to predict a celestial + event such as an eclipse. In the latter case, a new era might mark the + introduction of new astronomical or calendrical models. + + Sexagenary cycles were used to count years, months, days, and fractions of + a day using the set of Celestial Stems and Terrestrial Branches. Use of + the sixty-day cycle is seen in the earliest astronomical records. By + contrast the sixty-year cycle was introduced in the first century C.E. or + possibly a century earlier. Although the day count has fallen into disuse + in everyday life, it is still tabulated in calendars. The initial year + (jia-zi) of the current year cycle began on 1984 February 2, which is the + third day (bing-yin) of the day cycle. + + Details of early calendars + + One of the two methods that they used to make this calendar was to add an + extra month of 29 or 30 days, which they termed the 13th month, to the end + of a regular 12-month year. There is also evidence that suggests that the + Chinese developed the Metonic cycle (see above Complex cycles) - i.e., 19 + years with a total of 235 months-a century ahead of Meton's first + calculation (no later than the Spring and Autumn period, 770-476 BC). + During this cycle of 19 years there were seven intercalations of months. + The other method, which was abandoned soon after the Shang started to + adopt it, was to insert an extra month between any two months of a regular + year. Possibly, a lack of astronomical and arithmetical knowledge allowed + them to do this. + + By the 3rd century BC, the first method of intercalation was gradually + falling into disfavour, while the establishment of the meteorological + cycle, the erh-shih-ssu chieh-ch'i (Pinyin ershisi jieqi), during this + period officially revised the second method. This meteorological cycle + contained 24 points, each beginning one of the periods named consecutively + the Spring Begins, the Rain Water, the Excited Insects, the Vernal + Equinox, the Clear and Bright, the Grain Rains, the Summer Begins, the + Grain Fills, the Grain in Ear, the Summer Solstice, the Slight Heat, the + Great Heat, the Autumn Begins, the Limit of Heat, the White Dew, the + Autumn Equinox, the Cold Dew, the Hoar Frost Descends, the Winter Begins, + the Little Snow, the Heavy Snow, the Winter Solstice, the Little Cold, and + the Severe Cold. The establishment of this cycle required a fair amount of + astronomical understanding of the Earth as a celestial body, and without + elaborate equipment it is impossible to collect the necessary information. + Modern scholars acknowledge the superiority of pre-Sung Chinese astronomy + (at least until about the 13th century AD) over that of other, + contemporary nations. + + The 24 points within the meteorological cycle coincide with points 15-o + apart on the ecliptic (the plane of the Earth's yearly journey around the + Sun or, if it is thought that the Sun turns around the Earth, the apparent + journey of the Sun against the stars). It takes about 15.2 days for the + Sun to travel from one of these points to another (because the ecliptic is + a complete circle of 360-o), and the Sun needs 365 1/4 days to finish its + journey in this cycle. Supposedly, each of the 12 months of the year + contains two points, but, because a lunar month has only 29 1/2 days and + the two points share about 30.4 days, there is always the chance that a + lunar month will fail to contain both points, though the distance between + any two given points is only 15-o. If such an occasion occurs, the + intercalation of an extra month takes place. For instance, one may find a + year with two "Julys" or with two "Augusts" in the Chinese calendar. In + fact, the exact length of the month in the Chinese calendar is either 30 + days or 29 days-a phenomenon which reflects its lunar origin. Also, the + meteorological cycle means essentially a solar year. The Chinese thus + consider their calendar as yin-yang li, or a "lunar-solar calendar." + + When were foreign calendars introduced? + + Although the yin-yang li has been continuously employed by the Chinese, + foreign calendars were introduced to the Chinese, the Hindu calendar, for + instance, during the T'ang (Tang) dynasty (618-907), and were once used + concurrently with the native calendar. This situation also held true for + the Muslim calendar, which was introduced during the Yuean dynasty + (1206-1368). The Gregorian calendar was taken to China by Jesuit + missionaries in 1582, the very year that it was first used by Europeans. + Not until 1912, after the general public adopted the Gregorian calendar, + did the yin-yang li lose its primary importance. + + Western (pre-Copernican) astronomical theories were introduced to China by + Jesuit missionaries in the seventeenth century. Gradually, more modern + Western concepts became known. Following the revolution of 1911, the + traditional practice of counting years from the accession of an emperor + was abolished. + + Made with SpicyNodes| Books | Museum store | Credits & feedback + + Copyright (c) 2008 IDEA -- webexhibits.org/calendars + + References + + Visible links + . Calendars exhibit + http://www.webexhibits.org/calendars/ + . Webexhibit + http://webexhibits.org/ + . http://www.webexhibits.org/calendars/index.html + . http://www.webexhibits.org/calendars/nodes.html + . http://www.webexhibits.org/calendars/year.html + . http://www.webexhibits.org/calendars/calendar.html + . http://www.webexhibits.org/calendars/week.html + . http://www.webexhibits.org/calendars/timeline.html + . http://www.webexhibits.org/calendars/introduction.html + . http://www.webexhibits.org/calendars/calendar.html + . http://www.webexhibits.org/calendars/calendar-chinese.html + . http://www.webexhibits.org/calendars/calendar-christian.html + . http://www.webexhibits.org/calendars/calendar-indian.html + . http://www.webexhibits.org/calendars/calendar-islamic.html + . http://www.webexhibits.org/calendars/calendar-jewish.html + . http://www.webexhibits.org/calendars/calendar-other.html + . http://www.webexhibits.org/calendars/calendar-ancient.html + . http://www.webexhibits.org/calendars/calendar-french.html + . http://www.webexhibits.org/calendars/calendar-future.html + . http://www.webexhibits.org/calendars/calendar-mayan.html + . http://www.webexhibits.org/calendars/calendar-roman.html + . http://www.webexhibits.org/calendars/calendar-chinese.html#anchor-chinese-year + . http://www.webexhibits.org/calendars/calendar-chinese.html#anchor-leap-years + . http://www.webexhibits.org/calendars/calendar-chinese.html#anchor-count-years + . http://www.webexhibits.org/calendars/calendar-chinese.html#anchor-chinese-calendar + . http://www.webexhibits.org/calendars/calendar-chinese.html#anchor-2033 + . http://www.webexhibits.org/calendars/calendar-chinese.html#anchor-really-start + . http://www.webexhibits.org/calendars/calendar-chinese.html#anchor-early-chinese + . http://www.webexhibits.org/calendars/calendar-chinese.html#anchor-details-early + . http://www.webexhibits.org/calendars/calendar-chinese.html#anchor-foreign-calendars + . Books + http://www.webexhibits.org/calendars/books.html + . Museum store + http://www.webexhibits.org/calendars/museumstore.html + . Credits & feedback + http://www.webexhibits.org/calendars/credits.html + . IDEA + http://idea.org/ + . calendars + http://webexhibits.org/calendars Added: user/edwin/calendar/cny.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/edwin/calendar/cny.c Fri Jan 29 06:39:57 2010 (r203154) @@ -0,0 +1,10 @@ +/* + * Last new moon before Chinese spring season. + * Chinese spring starts when the sun's longitude is 0 at Vernal Equinox. + * + * All the astronomical calculations are carried out for the meridian 120 + * degrees east of Greenwich. + * + * See the file chinesecalendar.txt or the URL + * http://www.webexhibits.org/calendars/calendar-chinese.html + */ Modified: user/edwin/calendar/io.c ============================================================================== --- user/edwin/calendar/io.c Fri Jan 29 05:44:20 2010 (r203153) +++ user/edwin/calendar/io.c Fri Jan 29 06:39:57 2010 (r203154) @@ -70,6 +70,7 @@ const char *calendarNoMail = "nomail"; / char path[MAXPATHLEN]; struct fixs neaster, npaskha, ncny, nfullmoon, nnewmoon; +struct fixs nmarequinox, nsepequinox, njunsolstice, ndecsolstice; struct iovec header[] = { {"From: ", 6}, @@ -82,6 +83,15 @@ struct iovec header[] = { }; #define MAXCOUNT 55 +#define REPLACE(string, slen, struct_) \ + if (strncasecmp(buf, (string), (slen)) == 0 && buf[(slen)]) { \ + if (struct_.name != NULL) \ + free(struct_.name); \ + if ((struct_.name = strdup(buf + (slen))) == NULL) \ + errx(1, "cannot allocate memory"); \ + struct_.len = strlen(buf + (slen)); \ + continue; \ + } void cal(void) { @@ -121,53 +131,22 @@ cal(void) if (buf[0] == '\0') continue; - /* Parse special definitions: LANG, Easter and Paskha */ + /* Parse special definitions: LANG, Easter, Paskha etc */ if (strncmp(buf, "LANG=", 5) == 0) { (void)setlocale(LC_ALL, buf + 5); d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); setnnames(); continue; } - if (strncasecmp(buf, "Easter=", 7) == 0 && buf[7]) { - if (neaster.name != NULL) - free(neaster.name); - if ((neaster.name = strdup(buf + 7)) == NULL) - errx(1, "cannot allocate memory"); - neaster.len = strlen(buf + 7); - continue; - } - if (strncasecmp(buf, "Paskha=", 7) == 0 && buf[7]) { - if (npaskha.name != NULL) - free(npaskha.name); - if ((npaskha.name = strdup(buf + 7)) == NULL) - errx(1, "cannot allocate memory"); - npaskha.len = strlen(buf + 7); - continue; - } - if (strncasecmp(buf, "ChineseNewYear=", 15) == 0 && buf[15]) { - if (ncny.name != NULL) - free(ncny.name); - if ((ncny.name = strdup(buf + 15)) == NULL) - errx(1, "cannot allocate memory"); - ncny.len = strlen(buf + 15); - continue; - } - if (strncasecmp(buf, "NewMoon=", 8) == 0 && buf[8]) { - if (nnewmoon.name != NULL) - free(nnewmoon.name); - if ((nnewmoon.name = strdup(buf + 8)) == NULL) - errx(1, "cannot allocate memory"); - nnewmoon.len = strlen(buf + 8); - continue; - } - if (strncasecmp(buf, "FullMoon=", 9) == 0 && buf[9]) { - if (nfullmoon.name != NULL) - free(nfullmoon.name); - if ((nfullmoon.name = strdup(buf + 9)) == NULL) - errx(1, "cannot allocate memory"); - nfullmoon.len = strlen(buf + 9); - continue; - } + REPLACE("Easter=", 7, neaster); + REPLACE("Paskha=", 7, npaskha); + REPLACE("ChineseNewYear=", 15, ncny); + REPLACE("NewMoon=", 8, nnewmoon); + REPLACE("FullMoon=", 9, nfullmoon); + REPLACE("MarEquinox=", 11, nmarequinox); + REPLACE("SepEquinox=", 11, nsepequinox); + REPLACE("JunSolstice=", 12, njunsolstice); + REPLACE("DecSolstice=", 12, ndecsolstice); /* * If the line starts with a tab, the data has to be Modified: user/edwin/calendar/ostern.c ============================================================================== --- user/edwin/calendar/ostern.c Fri Jan 29 05:44:20 2010 (r203153) +++ user/edwin/calendar/ostern.c Fri Jan 29 06:39:57 2010 (r203154) @@ -65,45 +65,3 @@ easter(int year) /* 0 ... abcd, NOT sinc else return 31 + 28 + 21 + L + 7; } - -/* return year day for Easter or easter depending days - * Match: Easter([+-][0-9]+)? - * e.g: Easter-2 is Good Friday (2 days before Easter) - */ - -int -geteaster(char *s, int year) -{ - int offset = 0; - -#define EASTER "easter" -#define EASTERNAMELEN (sizeof(EASTER) - 1) - - if (strncasecmp(s, EASTER, EASTERNAMELEN) == 0) - s += EASTERNAMELEN; - else if (neaster.name != NULL - && strncasecmp(s, neaster.name, neaster.len) == 0) - s += neaster.len; - else - return (0); - -#ifdef DEBUG - printf("%s %d %d\n", s, year, EASTERNAMELEN); -#endif - - /* Easter+1 or Easter-2 - * ^ ^ */ - - switch (*s) { - - case '-': - case '+': - offset = atoi(s); - break; - - default: - offset = 0; - } - - return (easter(year) + offset); -} Modified: user/edwin/calendar/parsedata.c ============================================================================== --- user/edwin/calendar/parsedata.c Fri Jan 29 05:44:20 2010 (r203153) +++ user/edwin/calendar/parsedata.c Fri Jan 29 06:39:57 2010 (r203154) @@ -79,7 +79,7 @@ static int parseoffset(char *s); * SpecialDay ::= 'Easter' | 'Pashka' | 'ChineseNewYear' * */ -int +static int determinestyle(char *date, int *flags, char *month, int *imonth, char *dayofmonth, int *idayofmonth, char *dayofweek, int *idayofweek, char *modifieroffset, @@ -135,6 +135,22 @@ determinestyle(char *date, int *flags, CHECKSPECIAL(date, STRING_EASTER, strlen(STRING_EASTER), F_EASTER); CHECKSPECIAL(date, neaster.name, neaster.len, F_EASTER); + CHECKSPECIAL(date, STRING_MAREQUINOX, + strlen(STRING_MAREQUINOX), F_MAREQUINOX); + CHECKSPECIAL(date, nmarequinox.name, nmarequinox.len, + F_SEPEQUINOX); + CHECKSPECIAL(date, STRING_SEPEQUINOX, + strlen(STRING_SEPEQUINOX), F_SEPEQUINOX); + CHECKSPECIAL(date, nsepequinox.name, nsepequinox.len, + F_SEPEQUINOX); + CHECKSPECIAL(date, STRING_JUNSOLSTICE, + strlen(STRING_JUNSOLSTICE), F_JUNSOLSTICE); + CHECKSPECIAL(date, njunsolstice.name, njunsolstice.len, + F_JUNSOLSTICE); + CHECKSPECIAL(date, STRING_DECSOLSTICE, + strlen(STRING_DECSOLSTICE), F_DECSOLSTICE); + CHECKSPECIAL(date, ndecsolstice.name, ndecsolstice.len, + F_DECSOLSTICE); if (checkdayofweek(date, &len, &offset, &dow) != 0) { *flags |= F_DAYOFWEEK; *flags |= F_VARIABLE; @@ -286,7 +302,7 @@ remember(int index, int *y, int *m, int d[index] = dd; } -void +static void debug_determinestyle(int dateonly, char *date, int flags, char *month, int imonth, char *dayofmonth, int idayofmonth, char *dayofweek, int idayofweek, char *modifieroffset, char *modifierindex, char *specialday) @@ -332,6 +348,7 @@ parsedaymonth(char *date, int *yearp, in int ieaster, ipaskha; int ifullmoon[MAXMOONS], inewmoon[MAXMOONS]; + int equinoxdays[2], solsticedays[2]; int *mondays, d, m, dow, rm, rd, offset; @@ -366,9 +383,11 @@ parsedaymonth(char *date, int *yearp, in index = 0; for (year = year1; year <= year2; year++) { + /* Get important dates for this year */ mondays = mondaytab[isleap(year)]; ieaster = easter(year); pom(year, ifullmoon, inewmoon); + equinoxsolstice(year, 0.0, equinoxdays, solsticedays); /* Same day every year */ if (*flags == (F_MONTH | F_DAYOFMONTH)) { @@ -531,11 +550,58 @@ parsedaymonth(char *date, int *yearp, in continue; } + /* (Mar|Sep)Equinox */ + if ((*flags & ~F_MODIFIEROFFSET) == + (F_SPECIALDAY | F_VARIABLE | F_MAREQUINOX)) { + offset = 0; + if ((*flags & F_MODIFIEROFFSET) != 0) + offset = parseoffset(modifieroffset); + if (remember_yd(year, equinoxdays[0] + offset, + &rm, &rd)) + remember(index++, yearp, monthp, dayp, + year, rm, rd); + continue; + } + if ((*flags & ~F_MODIFIEROFFSET) == + (F_SPECIALDAY | F_VARIABLE | F_SEPEQUINOX)) { + offset = 0; + if ((*flags & F_MODIFIEROFFSET) != 0) + offset = parseoffset(modifieroffset); + if (remember_yd(year, equinoxdays[1] + offset, + &rm, &rd)) + remember(index++, yearp, monthp, dayp, + year, rm, rd); + continue; + } + + /* (Jun|Dec)Solstice */ + if ((*flags & ~F_MODIFIEROFFSET) == + (F_SPECIALDAY | F_VARIABLE | F_JUNSOLSTICE)) { + offset = 0; + if ((*flags & F_MODIFIEROFFSET) != 0) + offset = parseoffset(modifieroffset); + if (remember_yd(year, solsticedays[0] + offset, + &rm, &rd)) + remember(index++, yearp, monthp, dayp, + year, rm, rd); + continue; + } + if ((*flags & ~F_MODIFIEROFFSET) == + (F_SPECIALDAY | F_VARIABLE | F_DECSOLSTICE)) { + offset = 0; + if ((*flags & F_MODIFIEROFFSET) != 0) + offset = parseoffset(modifieroffset); + if (remember_yd(year, solsticedays[1] + offset, + &rm, &rd)) + remember(index++, yearp, monthp, dayp, + year, rm, rd); + continue; + } + printf("Unprocessed:\n"); debug_determinestyle(2, date, *flags, month, imonth, dayofmonth, idayofmonth, dayofweek, idayofweek, modifieroffset, modifierindex, specialday); - } return (index); @@ -575,6 +641,14 @@ showflags(int flags) strcat(s, "fullmoon "); if ((flags & F_NEWMOON) != 0) strcat(s, "newmoon "); + if ((flags & F_MAREQUINOX) != 0) + strcat(s, "marequinox "); + if ((flags & F_SEPEQUINOX) != 0) + strcat(s, "sepequinox "); + if ((flags & F_JUNSOLSTICE) != 0) + strcat(s, "junsolstice "); + if ((flags & F_DECSOLSTICE) != 0) + strcat(s, "decsolstice "); return s; } Modified: user/edwin/calendar/paskha.c ============================================================================== --- user/edwin/calendar/paskha.c Fri Jan 29 05:44:20 2010 (r203153) +++ user/edwin/calendar/paskha.c Fri Jan 29 06:39:57 2010 (r203154) @@ -55,36 +55,3 @@ paskha(int R) /*year*/ cumday = cumdaytab[isleap(R)]; return (((cumday[3] + 1) + 22) + (d + e)); } - -/* return year day for Orthodox Easter depending days */ - -int -getpaskha(char *s, int year) -{ - int offset; - - if (strncasecmp(s, PASKHA, PASKHALEN) == 0) - s += PASKHALEN; - else if (npaskha.name != NULL - && strncasecmp(s, npaskha.name, npaskha.len) == 0) - s += npaskha.len; - else - return 0; - - /* Paskha+1 or Paskha-2 - * ^ ^ */ - - switch (*s) { - - case '-': - case '+': - offset = atoi(s); - break; - - default: - offset = 0; - break; - } - - return (paskha(year) + offset + 13 /* new style */); -} Added: user/edwin/calendar/sunpos.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/edwin/calendar/sunpos.c Fri Jan 29 06:39:57 2010 (r203154) @@ -0,0 +1,345 @@ +/*- + * Copyright (c) 2009-2010 Edwin Groothuis. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +/* + * This code is created to match the formulas available at: + * Formula and examples obtained from "How to Calculate alt/az: SAAO" at + * http://www.saao.ac.za/public-info/sun-moon-stars/sun-index/how-to-calculate-altaz/ + */ + +#include +#include +#include +#include +#include +#include +#include "calendar.h" + +#define D2R(m) ((m) / 180 * M_PI) +#define R2D(m) ((m) * 180 / M_PI) + +#define SIN(x) (sin(D2R(x))) +#define COS(x) (cos(D2R(x))) +#define TAN(x) (tan(D2R(x))) +#define ASIN(x) (R2D(asin(x))) +#define ATAN(x) (R2D(atan(x))) + +#ifdef NOTDEF +static void +comp(char *s, double v, double c) +{ + + printf("%-*s %*g %*g %*g\n", 15, s, 15, v, 15, c, 15, v - c); +} + +int expY; +double expZJ = 30.5; +double expUTHM = 8.5; +double expD = 34743.854; +double expT = 0.9512349; +double expL = 324.885; +double expM = 42.029; +double expepsilon = 23.4396; +double explambda = 326.186; +double expalpha = 328.428; +double expDEC = -12.789; +double expeastlongitude = 17.10; +double explatitude = -22.57; +double expHA = -37.673; +double expALT = 49.822; +double expAZ = 67.49; +#endif + +static double +fixup(double *d) +{ + + if (*d < 0) { + while (*d < 0) + *d += 360; + } else { + while (*d > 360) + *d -= 360; + } + + return (*d); +} + +static double ZJtable[] = { + 0, -0.5, 30.5, 58.5, 89.5, 119.5, 150.5, 180.5, 211.5, 242.5, 272.5, 303.5, 333.5 }; + +static void +sunpos(int inYY, int inMM, int inDD, double UTCOFFSET, int inHOUR, int inMIN, + double eastlongitude, double latitude, double *DEC, double *ALT, double *AZ) +{ + int Y; + double ZJ, D, T, L, M, epsilon, lambda, alpha, HA, UTHM; + + /* Not calculated in this code */ + *ALT = 0; + *AZ = 0; + + ZJ = ZJtable[inMM]; + if (inMM <= 2 && isleap(inYY)) + ZJ -= 1.0; + + UTHM = inHOUR + inMIN / 60.0 + UTCOFFSET; + Y = inYY - 1900; /* 1 */ + D = floor(365.25 * Y) + ZJ + inDD + UTHM / 24; /* 3 */ + T = D / 36525.0; /* 4 */ + L = 279.697 + 36000.769 * T; /* 5 */ + fixup(&L); + M = 358.476 + 35999.050 * T; /* 6 */ + fixup(&M); + epsilon = 23.452 - 0.013 * T; /* 7 */ + fixup(&epsilon); + + lambda = L + (1.919 - 0.005 * T) * SIN(M) + 0.020 * SIN(2 * M); /* 8 */ + fixup(&lambda); + alpha = ATAN(TAN(lambda) * COS(epsilon)); /* 9 */ + + /* Alpha should be in the same quadrant as lamba */ + if (1) { + int lssign = sin(D2R(lambda)) < 0 ? -1 : 1; + int lcsign = cos(D2R(lambda)) < 0 ? -1 : 1; + while (((sin(D2R(alpha)) < 0) ? -1 : 1) != lssign + || ((cos(D2R(alpha)) < 0) ? -1 : 1) != lcsign) + alpha += 90.0; + } + fixup(&alpha); + + *DEC = ASIN(SIN(lambda) * SIN(epsilon)); /* 10 */ + fixup(DEC); + fixup(&eastlongitude); + HA = L - alpha + 180 + 15 * UTHM + eastlongitude; /* 12 */ + fixup(&HA); + fixup(&latitude); +#ifdef NOTDEF + printf("%02d/%02d %02d: l:%g d:%g h:%g\n", + inMM, inDD, inHOUR, latitude, *DEC, HA); +#endif + return; + + /* + * The following calculations are not used, so to save time + * they are not calculated. + */ +#ifdef NOTDEF + *ALT = ASIN(SIN(latitude) * SIN(*DEC) + + COS(latitude) * COS(*DEC) * COS(HA)); /* 13 */ + fixup(ALT); + *AZ = ATAN(SIN(HA) / + (COS(HA) * SIN(latitude) - TAN(*DEC) * COS(latitude))); /* 14 */ + + if (*ALT > 180) + *ALT -= 360; + if (*ALT < -180) + *ALT += 360; + printf("a:%g a:%g\n", *ALT, *AZ); +#endif + +#ifdef NOTDEF + printf("Y:\t\t\t %d\t\t %d\t\t %d\n", Y, expY, Y - expY); + comp("ZJ", ZJ, expZJ); + comp("UTHM", UTHM, expUTHM); + comp("D", D, expD); + comp("T", T, expT); + comp("L", L, fixup(&expL)); + comp("M", M, fixup(&expM)); + comp("epsilon", epsilon, fixup(&expepsilon)); + comp("lambda", lambda, fixup(&explambda)); + comp("alpha", alpha, fixup(&expalpha)); + comp("DEC", DEC, fixup(&expDEC)); + comp("eastlongitude", eastlongitude, fixup(&expeastlongitude)); + comp("latitude", latitude, fixup(&explatitude)); + comp("HA", HA, fixup(&expHA)); + comp("ALT", ALT, fixup(&expALT)); + comp("AZ", AZ, fixup(&expAZ)); +#endif +} + + +#define SIGN(a) (((a) > 180) ? -1 : 1) +#define ANGLE(a, b) (((a) < (b)) ? 1 : -1) +#define HOUR(h) ((h) / 4) +#define MIN(h) (15 * ((h) % 4)) +#define DEBUG1(y, m, d, hh, mm, pdec, dec) \ + printf("%4d-%02d-%02d %02d:%02d:00 - %7.7g -> %7.7g\n", \ + y, m, d, hh, mm, pdec, dec) +#define DEBUG2(y, m, d, hh, mm, pdec, dec, pang, ang) \ + printf("%4d-%02d-%02d %02d:%02d:00 - %7.7g -> %7.7g - %d -> %d\n", \ + y, m, d, hh, mm, pdec, dec, pang, ang) *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***