Download as pdf or txt
Download as pdf or txt
You are on page 1of 63

Asynchronous Programming in Rust 1 /

converted Edition Carl Fredrik Samson


Visit to download the full and correct content document:
https://textbookfull.com/product/asynchronous-programming-in-rust-1-converted-editi
on-carl-fredrik-samson/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Asynchronous Programming in Rust 1st Edition Carl


Fredrik Samson

https://textbookfull.com/product/asynchronous-programming-in-
rust-1st-edition-carl-fredrik-samson/

Asynchronous Programming in Rust: Learn asynchronous


programming by building working examples of futures,
green threads, and runtimes 1st Edition Carl Fredrik
Samson
https://textbookfull.com/product/asynchronous-programming-in-
rust-learn-asynchronous-programming-by-building-working-examples-
of-futures-green-threads-and-runtimes-1st-edition-carl-fredrik-
samson/

Asynchronous Android Programming Helder Vasconcelos

https://textbookfull.com/product/asynchronous-android-
programming-helder-vasconcelos/

The Rust Programming Language Covers Rust 2018 Steve


Klabnik

https://textbookfull.com/product/the-rust-programming-language-
covers-rust-2018-steve-klabnik/
Programming Rust 1st Edition Jim Blandy

https://textbookfull.com/product/programming-rust-1st-edition-
jim-blandy/

Hands On Functional Programming in Rust 1st Edition


Andrew Johnson

https://textbookfull.com/product/hands-on-functional-programming-
in-rust-1st-edition-andrew-johnson/

Cell Based Assays Using iPSCs for Drug Development and


Testing Carl-Fredrik Mandenius

https://textbookfull.com/product/cell-based-assays-using-ipscs-
for-drug-development-and-testing-carl-fredrik-mandenius/

Combine Asynchronous Programming with Swift First


Edition Scott Gardner

https://textbookfull.com/product/combine-asynchronous-
programming-with-swift-first-edition-scott-gardner/

Combine Asynchronous Programming with Swift First


Edition Scott Gardner

https://textbookfull.com/product/combine-asynchronous-
programming-with-swift-first-edition-scott-gardner-2/
Asynchronous Programming in Rust
Copyright © 2024 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the publisher,
except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information
presented. However, the information contained in this book is sold without warranty, either express or
implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for
any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and
products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot
guarantee the accuracy of this information.

Publishing Product Manager: Samriddhi Murarka

Group Product Manager: Kunal Sawant

Senior Editor: Kinnari Chohan

Technical Editor: Rajdeep Chakraborty

Copy Editor: Safis Editing

Project Coordinator: Manisha Singh

Indexer: Rekha Nair

Production Designer: Joshua Misquitta

Marketing DevRel Coordinator: Sonia Chauhan

First published: February 2024

Production reference: 2020224

Published by Packt Publishing Ltd.


Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80512-813-7

www.packtpub.com
To my family—my brother, my parents, and especially my beloved wife and fantastic children
that make every day an absolute joy.
– Carl Fredrik Samson

Contributors

About the author


Carl Fredrik Samson is a popular technology writer and has been active in the Rust community
since 2018. He has an MSc in Business Administration where he specialized in strategy and finance.
When not writing, he’s a father of two children and a CEO of a company with 300 employees. He’s
been interested in different kinds of technologies his whole life and his programming experience
ranges from programming against old IBM mainframes to modern cloud computing, using everything
from assembly to Visual Basic for Applications. He has contributed to several open source projects
including the official documentation for asynchronous Rust.

I want to thank the Rust community for being so constructive, positive and welcoming. This book
would not have happened had it not been for all the positive and insightful interaction with the
community. A special thanks goes to the implementors of all the libraries that underpins the async
ecosystem today like mio, Tokio, and async-std.

I also want to thank my editor, Kinnari, who has been extraordinarily patient and helpful during the
process of writing this book.

About the reviewer


Evgeni Pirianov is an experienced Senior Software Engineer with a deep expertise in Backend
Technologies, Web3 an Blockchain. Evgeni has graduated with a degree in Engineering from
Imperial College, London and has worked for a few years developing non-linear solvers in C++ .
Ever since, he has been at the forefront of architecturing, designing, and implementing decentralized
applications in the fields of Defi and Metaverse. Evgeni’s passion for Rust is unsurpassed and he is a
true believer of its bright future and wide range of applications.

Yage Hu is a software engineer specializing in systems programming and computer architecture. He


has cut code in companies such as Uber, Amazon, and Meta and is currently conducting systems
research with WebAssembly and Rust. Yage and his wife have just welcomed their first child,
Maxine.
Table of Contents

Preface
Part 1: Asynchronous Programming Fundamentals

Concurrency and Asynchronous Programming: a


Detailed Overview
Technical requirements
An evolutionary journey of multitasking
Non-preemptive multitasking
Preemptive multitasking
Hyper-threading
Multicore processors
Do you really write synchronous code?
Concurrency versus parallelism
The mental model I use
Let’s draw some parallels to process economics
Concurrency and its relation to I/O
What about threads provided by the operating system?
Choosing the right reference frame
Asynchronous versus concurrent
The role of the operating system
Concurrency from the operating system’s perspective
Teaming up with the operating system
Communicating with the operating system
The CPU and the operating system
Down the rabbit hole
How does the CPU prevent us from accessing memory we’re not
supposed to access?
But can’t we just change the page table in the CPU?
Interrupts, firmware, and I/O
A simplified overview
Interrupts
Firmware
Summary

How Programming Languages Model Asynchronous


Program Flow
Definitions
Threads
Threads provided by the operating system
Creating new threads takes time
Each thread has its own stack
Context switching
Scheduling
The advantage of decoupling asynchronous operations from OS
threads
Example
Fibers and green threads
Each stack has a fixed space
Context switching
Scheduling
FFI
Callback based approaches
Coroutines: promises and futures
Coroutines and async/await
Summary
3

Understanding OS-Backed Event Queues, System


Calls, and Cross-Platform Abstractions
Technical requirements
Running the Linux examples
Why use an OS-backed event queue?
Blocking I/O
Non-blocking I/O
Event queuing via epoll/kqueue and IOCP
Readiness-based event queues
Completion-based event queues
epoll, kqueue, and IOCP
Cross-platform event queues
System calls, FFI, and cross-platform abstractions
The lowest level of abstraction
The next level of abstraction
The highest level of abstraction
Summary
Part 2: Event Queues and Green Threads

Create Your Own Event Queue


Technical requirements
Design and introduction to epoll
Is all I/O blocking?
The ffi module
Bitflags and bitmasks
Level-triggered versus edge-triggered events
The Poll module
The main program
Summary

Creating Our Own Fibers


Technical requirements
How to use the repository alongside the book
Background information
Instruction sets, hardware architectures, and ABIs
The System V ABI for x86-64
A quick introduction to Assembly language
An example we can build upon
Setting up our project
An introduction to Rust inline assembly macro
Running our example
The stack
What does the stack look like?
Stack sizes
Implementing our own fibers
Implementing the runtime
Guard, skip, and switch functions
Finishing thoughts
Summary
Part 3: Futures and async/await in Rust

Futures in Rust
What is a future?
Leaf futures
Non-leaf futures
A mental model of an async runtime
What the Rust language and standard library take care of
I/O vs CPU-intensive tasks
Summary

Coroutines and async/await


Technical requirements
Introduction to stackless coroutines
An example of hand-written coroutines
Futures module
HTTP module
Do all futures have to be lazy?
Creating coroutines
async/await
coroutine/wait
corofy—the coroutine preprocessor
b-async-await—an example of a coroutine/wait transformation
c-async-await—concurrent futures
Final thoughts
Summary

Runtimes, Wakers, and the Reactor-Executor Pattern


Technical requirements
Introduction to runtimes and why we need them
Reactors and executors
Improving our base example
Design
Changing the current implementation
Creating a proper runtime
Step 1 – Improving our runtime design by adding a Reactor and
a Waker
Creating a Waker
Changing the Future definition
Step 2 – Implementing a proper Executor
Step 3 – Implementing a proper Reactor
Experimenting with our new runtime
An example using concurrency
Running multiple futures concurrently and in parallel
Summary

Coroutines, Self-Referential Structs, and Pinning


Technical requirements
Improving our example 1 – variables
Setting up the base example
Improving our base example
Improving our example 2 – references
Improving our example 3 – this is… not… good…
Discovering self-referential structs
What is a move?
Pinning in Rust
Pinning in theory
Definitions
Pinning to the heap
Pinning to the stack
Pin projections and structural pinning
Improving our example 4 – pinning to the rescue
future.rs
http.rs
Main.rs
executor.rs
Summary

10

Creating Your Own Runtime


Technical requirements
Setting up our example
main.rs
future.rs
http.rs
executor.rs
reactor.rs
Experimenting with our runtime
Challenges with asynchronous Rust
Explicit versus implicit reactor instantiation
Ergonomics versus efficiency and flexibility
Common traits that everyone agrees about
Async drop
The future of asynchronous Rust
Summary
Epilogue

Index

Other Books You May Enjoy


Preface
The content in this book was initially written as a series of shorter books for programmers wanting to
learn asynchronous programming from the ground up using Rust. I found the existing material I came
upon at the time to be in equal parts frustrating, enlightening, and confusing, so I wanted to do
something about that.

Those shorter books became popular, so when I got the chance to write everything a second time,
improve the parts that I was happy with, and completely rewrite everything else and put it in a single,
coherent book, I just had to do it. The result is right in front of you.

People start programming for a variety of different reasons. Scientists start programming to model
problems and perform calculations. Business experts create programs that solve specific problems
that help their businesses. Some people start programming as a hobby or in their spare time. Common
to these programmers is that they learn programming from the top down.

Most of the time, this is perfectly fine, but on the topic of asynchronous programming in general, and
Rust in particular, there is a clear advantage to learning about the topic from first principles, and this
book aims to provide a means to do just that.

Asynchronous programming is a way to write programs where you divide your program into tasks
that can be stopped and resumed at specific points. This, in turn, allows a language runtime, or a
library, to drive and schedule these tasks so their progress interleaves.

Asynchronous programming will, by its very nature, affect the entire program flow, and it’s very
invasive. It rewrites, reorders, and schedules the program you write in a way that’s not always
obvious to you as a programmer.

Most programming languages try to make asynchronous programming so easy that you don’t really
have to understand how it works just to be productive in it.

You can get quite productive writing asynchronous Rust without really knowing how it works as
well, but Rust is more explicit and surfaces more complexity to the programmer than most other
languages. You will have a much easier time handling this complexity if you get a deep
understanding of asynchronous programming in general and what really happens when you write
asynchronous Rust.

Another huge upside is that learning from first principles results in knowledge that is applicable way
beyond Rust, and it will, in turn, make it easier to pick up asynchronous programming in other
languages as well. I would even go so far as to say that most of this knowledge will be useful even in
your day-to-day programming. At least, that’s how it’s been for me.
I want this book to feel like you’re joining me on a journey, where we build our knowledge topic by
topic and learn by creating examples and experiments along the way. I don’t want this book to feel
like a lecturer simply telling you how everything works.

This book is created for people who are curious by nature, the kind of programmers who want to
understand the systems they use, and who like creating small and big experiments as a way to explore
and learn.
Who this book is for
This book is for developers with some prior programming experience who want to learn
asynchronous programming from the ground up so they can be proficient in async Rust and be able to
participate in technical discussions on the subject. The book is perfect for those who like writing
working examples they can pick apart, expand, and experiment with.There are two kinds of personas
that I feel this book is especially relevant to:
Developers coming from higher-level languages with a garbage collector, interpreter, or runtime, such as C#, Java, JavaScript,
Python, Ruby, Swift, or Go. Programmers who have extensive experience with asynchronous programming in any of these
languages but want to learn it from the ground up and programmers with no experience with asynchronous programming should
both find this book equally useful.

Developers with experience in languages such as C or C++ that have limited experience with asynchronous programming.
What this book covers
Chapter 1, Concurrency and Asynchronous Programming: A Detailed Overview, provides a short
history leading up to the type of asynchronous programming we use today. We give several important
definitions and provide a mental model that explains what kind of problems asynchronous
programming really solves, and how concurrency differs from parallelism. We also cover the
importance of choosing the correct reference frame when discussing asynchronous program flow, and
we go through several important and fundamental concepts about CPUs, operating systems,
hardware, interrupts, and I/O.

Chapter 2, How Programming Languages Model Asynchronous Program Flow, narrows the scope
from the previous chapter and focuses on the different ways programming languages deal with
asynchronous programming. It starts by giving several important definitions before explaining
stackful and stackless coroutines, OS threads, green threads, fibers, callbacks, promises, futures, and
async/await.

Chapter 3, Understanding OS-Backed Event Queues, System Calls, and Cross-Platform Abstractions,
explains what epoll, kqueue, and IOCP are and how they differ. It prepares us for the next chapters by
giving an introduction to syscalls, FFI, and cross-platform abstractions.

Chapter 4, Create Your Own Event Queue, is the chapter where you create your own event queue that
mimics the API of mio (the popular Rust library that underpins much of the current async
ecosystem). The example will center around epoll and go into quite a bit of detail on how it works.

Chapter 5, Creating Our Own Fibers, walks through an example where we create our own kind of
stackful coroutines called fibers. They’re the same kind of green threads that Go uses and show one
of the most widespread and popular alternatives to the type of abstraction Rust uses with futures and
async/await today. Rust used this kind of abstraction in its early days before it reached 1.0, so it’s also
a part of Rust’s history. This chapter will also cover quite a few general programming concepts, such
as stacks, assembly, Application Binary Interfaces (ABIs), and instruction set architecture
(ISAs), that are useful beyond the context of asynchronous programming as well.

Chapter 6, Futures in Rust, gives a short introduction and overview of futures, runtimes, and
asynchronous programming in Rust.

Chapter 7, Coroutines and async/await, is a chapter where you write your own coroutines that are
simplified versions of the ones created by async/await in Rust today. We’ll write a few of them by
hand and introduce a new syntax that allows us to programmatically rewrite what look like regular
functions into the coroutines we wrote by hand.
Chapter 8, Runtimes, Wakers, and the Reactor-Executor Pattern, introduces runtimes and runtime
design. By iterating on the example we created in Chapter 7, we’ll create a runtime for our coroutines
that we’ll gradually improve. We’ll also do some experiments with our runtime once it’s done to
better understand how it works.

Chapter 9, Coroutines, Self-Referential Structs, and Pinning, is the chapter where we introduce self-
referential structs and pinning in Rust. By improving our coroutines further, we’ll experience first-
hand why we need something such as Pin, and how it helps us solve the problems we encounter.

Chapter 10, Create Your Own Runtime, is the chapter where we finally put all the pieces together.
We’ll improve the same example from the previous chapters further so we can run Rust futures,
which will allow us to use the full power of async/await and asynchronous Rust. We’ll also do a few
experiments that show some of the difficulties with asynchronous Rust and how we can best solve
them.

To get the most out of this book


You should have some prior programming experience and, preferably, some knowledge about Rust.
Reading the free, and excellent, introductory book The Rust Programming Language
(https://doc.rust-lang.org/book/) should give you more than enough knowledge about Rust to follow
along since any advanced topics will be explained step by step.

The ideal way to read this book is to have the book and a code editor open side by side. You should
also have the accompanying repository available so you can refer to that if you encounter any issues.

Software/hardware covered in the book Operating system requirements

Rust (version 1.51 or later) Windows, macOS, or Linux

You need Rust installed. If you haven’t already, follow the instructions here: https://www.rust-
lang.org/tools/install.

Some examples will require you to use Windows Subsystem for Linux (WSL) on Windows. If
you’re following along on a Windows machine, I recommend that you enable WSL
(https://learn.microsoft.com/en-us/windows/wsl/install) now and install Rust by following the
instructions for installing Rust on WSL here: https://www.rust-lang.org/tools/install.

If you are using the digital version of this book, we advise you to type the code yourself or
access the code from the book’s GitHub repository (a link is available in the next section).
Doing so will help you avoid any potential errors related to the copying and pasting of code.

The accompanying repository is organized in the following fashion:


Code that belongs to a specific chapter is in that chapter’s folder (e.g., ch01).

Each example is organized as a separate crate.

The letters in front of the example names indicate in what order the different examples are presented in the book. For example, the
a-runtime example comes before the b-reactor-executor example. This way, they will be ordered chronologically (at
least by default on most systems).

Some examples have a version postfixed with -bonus. These versions will be mentioned in the book text and often contain a
specific variant of the example that might be interesting to check out but is not important to the topic at hand.

Download the example code files


You can download the example code files for this book from GitHub at
https://github.com/PacktPublishing/Asynchronous-Programming-in-Rust. If there’s an update to the
code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at
https://github.com/PacktPublishing/. Check them out!

Conventions used
There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file
extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “So, now
we have created our own async runtime that uses Rust’s Futures, Waker, Context, and async/await.”

A block of code is set as follows:

pub trait Future {


type Output;
fn poll(&mut self) -> PollState<Self::Output>;
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items
are set in bold:

struct Coroutine0 {
stack: Stack0,
state: State0,
}

Any command-line input or output is written as follows:

$ cargo run

TIPS OR IMPORTANT NOTES


Appear like this.
Get in touch
Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at
[email protected] and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do
happen. If you have found a mistake in this book, we would be grateful if you would report this to us.
Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be
grateful if you would provide us with the location address or website name. Please contact us at
[email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you
are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share your thoughts


Once you’ve read Asynchronous Programming in Rust, we’d love to hear your thoughts! Please click
here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering
excellent quality content.

Download a free PDF copy of this book


Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical
books directly into your application.

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free
content in your inbox daily

Follow these simple steps to get the benefits:


1. Scan the QR code or visit the link below
https://packt.link/free-ebook/9781805128137

2. Submit your proof of purchase

3. That’s it! We’ll send your free PDF and other benefits to your email directly
Part 1:Asynchronous Programming Fundamentals
In this part, you’ll receive a thorough introduction to concurrency and asynchronous programming.
We’ll also explore various techniques that programming languages employ to model asynchrony,
examining the most popular ones and covering some of the pros and cons associated with each.
Finally, we’ll explain the concept of OS-backed event queues, such as epoll, kqueue, and IOCP,
detailing how system calls are used to interact with the operating system and addressing the
challenges encountered in creating cross-platform abstractions like mio. This section comprises the
following chapters:
Chapter 1, Concurrency and Asynchronous Programming: A Detailed Overview

Chapter 2, How Programming Languages Model Asynchronous Program Flow

Chapter 3, Understanding OS-Backed Event Queues, System Calls and Cross Platform Abstractions
1

Concurrency and Asynchronous Programming: a


Detailed Overview
Asynchronous programming is one of those topics many programmers find confusing. You come to
the point when you think you’ve got it, only to later realize that the rabbit hole is much deeper than
you thought. If you participate in discussions, listen to enough talks, and read about the topic on the
internet, you’ll probably also come across statements that seem to contradict each other. At least, this
describes how I felt when I first was introduced to the subject.

The cause of this confusion is often a lack of context, or authors assuming a specific context without
explicitly stating so, combined with terms surrounding concurrency and asynchronous programming
that are rather poorly defined.

In this chapter, we’ll be covering a lot of ground, and we’ll divide the content into the following main
topics:
Async history

Concurrency and parallelism

The operating system and the CPU

Interrupts, firmware, and I/O

This chapter is general in nature. It doesn’t specifically focus on Rust, or any specific programming
language for that matter, but it’s the kind of background information we need to go through so we
know that everyone is on the same page going forward. The upside is that this will be useful no
matter what programming language you use. In my eyes, that fact also makes this one of the most
interesting chapters in this book.

There’s not a lot of code in this chapter, so we’re off to a soft start. It’s a good time to make a cup of
tea, relax, and get comfortable, as we’re about start this journey together.

Technical requirements
All examples will be written in Rust, and you have two alternatives for running the examples:
Write and run the examples we’ll write on the Rust playground

Install Rust on your machine and run the examples locally (recommended)

The ideal way to read this chapter is to clone the accompanying repository
(https://github.com/PacktPublishing/Asynchronous-Programming-in-Rust/tree/main/ch01/a-
assembly-dereference) and open the ch01 folder and keep it open while you read the book. There,
you’ll find all the examples we write in this chapter and even some extra information that you might
find interesting as well. You can of course also go back to the repository later if you don’t have that
accessible right now.

An evolutionary journey of multitasking


In the beginning, computers had one CPU that executed a set of instructions written by a programmer
one by one. No operating system (OS), no scheduling, no threads, no multitasking. This was how
computers worked for a long time. We’re talking back when a program was assembled in a deck of
punched cards, and you got in big trouble if you were so unfortunate that you dropped the deck onto
the floor.

There were operating systems being researched very early and when personal computing started to
grow in the 80s, operating systems such as DOS were the standard on most consumer PCs.

These operating systems usually yielded control of the entire CPU to the program currently
executing, and it was up to the programmer to make things work and implement any kind of
multitasking for their program. This worked fine, but as interactive UIs using a mouse and windowed
operating systems became the norm, this model simply couldn’t work anymore.

Non-preemptive multitasking
Non-preemptive multitasking was the first method used to be able to keep a UI interactive (and
running background processes).

This kind of multitasking put the responsibility of letting the OS run other tasks, such as responding
to input from the mouse or running a background task, in the hands of the programmer.

Typically, the programmer yielded control to the OS.

Besides offloading a huge responsibility to every programmer writing a program for your platform,
this method was naturally error-prone. A small mistake in a program’s code could halt or crash the
entire system.

NOTE
Another popular term for what we call non-preemptive multitasking is cooperative multitasking. Windows 3.1 used
cooperative multitasking and required programmers to yield control to the OS by using specific system calls. One badly-
behaving application could thereby halt the entire system.

Preemptive multitasking
While non-preemptive multitasking sounded like a good idea, it turned out to create serious problems
as well. Letting every program and programmer out there be responsible for having a responsive UI
in an operating system can ultimately lead to a bad user experience, since every bug out there could
halt the entire system.

The solution was to place the responsibility of scheduling the CPU resources between the programs
that requested it (including the OS itself) in the hands of the OS. The OS can stop the execution of a
process, do something else, and switch back.

On such a system, if you write and run a program with a graphical user interface on a single-core
machine, the OS will stop your program to update the mouse position before it switches back to your
program to continue. This happens so frequently that we don’t usually observe any difference
whether the CPU has a lot of work or is idle.

The OS is responsible for scheduling tasks and does this by switching contexts on the CPU. This
process can happen many times each second, not only to keep the UI responsive but also to give
some time to other background tasks and IO events.

This is now the prevailing way to design an operating system.

NOTE
Later in this book, we’ll write our own green threads and cover a lot of basic knowledge about context switching, threads,
stacks, and scheduling that will give you more insight into this topic, so stay tuned.

Hyper-threading
As CPUs evolved and added more functionality such as several arithmetic logic units (ALUs) and
additional logic units, the CPU manufacturers realized that the entire CPU wasn't fully utilized. For
example, when an operation only required some parts of the CPU, an instruction could be run on the
ALU simultaneously. This became the start of hyper-threading.

Your computer today, for example, may have 6 cores and 12 logical cores.. This is exactly where
hyper-threading comes in. It “simulates” two cores on the same core by using unused parts of the
CPU to drive progress on thread 2 and simultaneously running the code on thread 1. It does this by
using a number of smart tricks (such as the one with the ALU).

Now, using hyper-threading, we could actually offload some work on one thread while keeping the
UI interactive by responding to events in the second thread even though we only had one CPU core,
thereby utilizing our hardware better.

YOU MIGHT WONDER ABOUT THE PERFORMANCE OF HYPER-


THREADING
It turns out that hyper-threading has been continuously improved since the 90s. Since you’re not actually running two
CPUs, there will be some operations that need to wait for each other to finish. The performance gain of hyper-threading
compared to multitasking in a single core seems to be somewhere close to 30% but it largely depends on the workload.

Multicore processors
As most know, the clock frequency of processors has been flat for a long time. Processors get faster
by improving caches, branch prediction, and speculative execution, and by working on the
processing pipelines of the processors, but the gains seem to be diminishing.

On the other hand, new processors are so small that they allow us to have many on the same chip.
Now, most CPUs have many cores and most often, each core will also have the ability to perform
hyper-threading.

Do you really write synchronous code?


Like many things, this depends on your perspective. From the perspective of your process and the
code you write, everything will normally happen in the order you write it.

From the operating system’s perspective, it might or might not interrupt your code, pause it, and run
some other code in the meantime before resuming your process.

From the perspective of the CPU, it will mostly execute instructions one at a time.* It doesn’t care
who wrote the code, though, so when a hardware interrupt happens, it will immediately stop and
give control to an interrupt handler. This is how the CPU handles concurrency.

NOTE
*However, modern CPUs can also do a lot of things in parallel. Most CPUs are pipelined, meaning that the next instruction
is loaded while the current one is executing. It might have a branch predictor that tries to figure out what instructions to
load next.

The processor can also reorder instructions by using out-of-order execution if it believes it makes things faster this way
without ‘asking’ or ‘telling’ the programmer or the OS, so you might not have any guarantee that A happens before B.

The CPU offloads some work to separate ‘coprocessors’ such as the FPU for floating-point calculations, leaving the main
CPU ready to do other tasks et cetera.

As a high-level overview, it’s OK to model the CPU as operating in a synchronous manner, but for now, let’s just make a
mental note that this is a model with some caveats that become especially important when talking about parallelism,
synchronization primitives (such as mutexes and atomics), and the security of computers and operating systems.

Concurrency versus parallelism


Right off the bat, we’ll dive into this subject by defining what concurrency is. Since it is quite easy
to confuse concurrent with parallel, we will try to make a clear distinction between the two from the
get-go.

IMPORTANT
Concurrency is about dealing with a lot of things at the same time.

Parallelism is about doing a lot of things at the same time.

We call the concept of progressing multiple tasks at the same time multitasking. There are two ways
to multitask. One is by progressing tasks concurrently, but not at the same time. Another is to
progress tasks at the exact same time in parallel. Figure 1.1 depicts the difference between the two
scenarios:

Figure 1.1 – Multitasking two tasks

First, we need to agree on some definitions:


Resource: This is something we need to be able to progress a task. Our resources are limited. This could be CPU time or memory.

Task: This is a set of operations that requires some kind of resource to progress. A task must consist of several sub-operations.

Parallel: This is something happening independently at the exact same time.

Concurrent: These are tasks that are in progress at the same time, but not necessarily progressing simultaneously.

This is an important distinction. If two tasks are running concurrently, but are not running in parallel,
they must be able to stop and resume their progress. We say that a task is interruptible if it allows for
Another random document with
no related content on Scribd:
wears sandals showing the motif of the obsidian snake, and his headdress is painted
with the stellar symbol, the round white spots on a black ground, which typifies the
night sky. Here also we see two bamboo staves attached to his neck—undoubtedly the
collar worn by captives or slaves which [93]rendered flight impossible, and which
Tezcatlipocâ wears to symbolize his enslavement of the Mexican people and in allusion
to his name Titlacauan, which means “He whose slaves we are.” The spear and the
net-pouch in this place recall the insignia of Mixcoatl, and seem to indicate that
Tezcatlipocâ was a god of the Chichimec or hunting folk of the North Steppes, or
perhaps it may merely symbolize the proneness of all stellar, lunar and solar deities in
Mexico to the chase.

Tonalamatl of the Aubin Collection.—In this manuscript Tezcatlipocâ appears as the


representative of the Moon-god and sits opposite the Sun-god. He is shown with his
usual attributes and face-painting, the smoking mirror in the region of the ear, the white
ring on his breast, and on his back the quetzalcomitl, the large quetzal-feather
ornament in which a banner is stuck. In his right hand he holds several of the agave-
spikes which the priests employed for piercing the tongue. In this manuscript the
Death-god is also depicted as Tezcatlipocâ, and wears his body-and-face painting and
his general insignia, as well as the rosette at the nape of the neck. In this place,
however, the snail-shaped shield rises above the forehead, which is also decorated
with a row of feather balls and a single arara plume.

(From Codex Vaticanus A, sheet 44 Verso.)


(From Codex Magliabecchiano, sheet 3, folio 89.)

TEZCATLIPOCÂ IN VARIOUS FORMS.

Codex Magliabecchiano.—A good illustration of Tezcatlipocâ will be found on page 89


of this codex. The figure of the god is surrounded by footprints, symbolic, probably, of
the circumstance that as the youngest and swiftest of the gods he arrived first at the
teotleco festival (coming of the gods) and impressed his footprint on the heap of maize
arranged by the priests for its reception in order that they might know of his coming. He
wears a large panache of green feathers, consisting of two parts; that immediately
above the face being inserted in a tumbler-shaped ornament painted blue, with a red
rim, and having six white disks upon its field. To the lower part of this is joined a
rainbow-like device in various colours, from which springs the main part of the feather
panache. The upper fore-part of the face is painted yellow, the rear portion purple or
grey, and [94]the region about the mouth is bright red. He is bearded. The tunic is white,
with a white shoulder-knot, and a bunch of maize springs from the right shoulder. On
the breast is the god’s mirror, and at the waist an ornament or symbol resembling the
Maya Kin (sun) sign, painted blue. The rest of the body-colour is purple-grey. In the left
hand he carries an atlatl, or spear-thrower, with a serpent’s head having a brown mane,
and bearing a resemblance to some horse-like ornamental motifs found in Guatemala.
In the right hand he bears a shield, the field of which is divided into two parts, the right
painted blue and bearing what would seem to be the nose-ornament of the pulque-
gods, whilst the left resembles the design found on the skirt of the Earth-goddess. The
shield is crossed behind by four darts and is surmounted by a befeathered banner. In
this place Tezcatlipocâ is undoubtedly represented in his variant of “the young warrior,”
as his equipment shows.

Sahagun MS. (Biblioteca del Palacio).—The god’s feather crown is set with obsidian
knives. His face is barred with horizontal lines of black, and on his back he carries a
basket filled with quetzal-feathers. His arm-ring is set with obsidian knives, and one-half
of his leg is painted black. On his legs and feet he wears shells and sandals, the latter
the so-called “obsidian sandals,” painted with a picture of the obsidian snake. His arms
are covered with paper fans. His shield is inlaid with feather balls, and in one of his
hands he holds the “seeing” or scrying implement tlachialoni.

Acosta, describing Tezcatlipocâ, says 42: “They called this idol Tezcallipuca, he was
made of black, shining stone like to Jayel, being attired with some Gentile devises after
their manner. It had ear-rings of gold and silver, and through the nether lip a small
canon of christall, in length half a foote, in the which they sometimes put a greene
feather, and sometimes an azure, which made it resemble sometimes an emerald and
sometimes a turquois. It had the haire broided and bound up with a haire-lace of gold
burnished, [95]at the end whereof did hang an eare of gold, with two fire-brands of
smoke painted therein which did signify the praires of the afflicted and sinners that he
heard, when they recommended themselves to him. Betwixt the two eares hanged a
number of small herons. He had a jewell hanging at his neck so great that it covered all
his stomake. Upon his armes bracelets of gold, upon his navill a rich, green stone, and
in his left hand a fanne of precious feathers, of greene, azure and yellow, which came
forth of a looking-glasse of gold, shining and well-burnished, and that signified, that
within this looking-glasse he saw whatever was done in the world. They called this
glasse or chaston of gold irlacheaya, 43 which signifies his glass for to look in. In his
right hand he held foure darts which signified the chastisement he gave to the wicked
for their sins.… They held this idoll Tescatlipuca for the god of drought, of famine,
barrenness and pestilence. And therefore they painted him in another form, being set in
great majesty upon a stoole, compassed in with a red curtin, painted and wrought with
the heads and bones of dead men. In the left hand it had a target with five pines, like
unto pine apples of cotton, and in the right a little dart with a threatening countenance,
and the arm stretched out as if he would cast it and from the target came foure darts. It
had the countenance of an angry man and in choller, the body all painted blacke and
the head full of quailes feathers.”
Bernal Diaz says of him (bk. vi. c. 91): “Then we saw on the other side on the left hand
there stood the other great image the same height as Huichilobos, and it had a face
like a bear 44 and eyes that shone, made of their mirrors which they call Tezcat, and the
body plastered with precious stones like that of Huichilobos, for they say that the two
are brothers; and this Tezcatepuca was the god of Hell and had charge of the souls of
the Mexicans, and his body was girt with figures like little devils with snakes’ tails.”

Face-mask.—When Cortéz landed at Vera Cruz, the [96]messengers of Motecuhzoma


tendered him, along with other presents, “the ornaments or finery with which
Tezcatlipocâ was decorated.” The mask belonging to this costume is still in existence,
and is to be seen in the room devoted to American antiquities in the British Museum. It
consists of a human skull encrusted with mosaic in alternate bands of black and green,
the nasal cavity being set with a red stone and the eyes with pyrites ringed with white.

Statuette.—A statuette of Tezcatlipocâ from the Valley of Mexico, and now in the Uhde
collection, shows the god as nude, with the exception of a loin-cloth and a flat
headdress, rising in the middle.

Tezcatlipocâ in His Black and Red Forms.—Tezcatlipocâ was regarded by the Mexican
people as possessing two definite forms, the Black and the Red. In this paragraph we
will deal only with the insignia of these and not with their mythological significance,
which we will attempt to explain in its proper place. Perhaps the best and most classical
examples of these forms we possess are to be observed on sheet 21 of Codex Borgia,
on both halves of which we see the two forms represented as parallel figures, closely
resembling one another in nearly every detail. It should at once be stated that the Red
Tezcatlipocâ is merely a variant of Xipe, and indeed in one place in Codex Vaticanus B
we observe that his loin-cloth forks in the swallow-tail fashion noticeable in the loin-
cloth of that god, and, generally speaking, the red colours he wears are those of the
roseate spoon-bill, the feathers of which are typical of Xipe’s dress. These pictures in
the Codex Borgia are supplemented by two on sheets 85 and 86 of Vaticanus B, where
the swallow-tail ends of the loin-cloth and the nasal rod show distinctly that the Red
Tezcatlipocâ is only a form of Xipe. The Black Tezcatlipocâ opposite him is, however,
represented with the striped body-paint of Tlauizcalpantecutli, the arms being entirely
black. In the Borgia paintings the Black Tezcatlipocâ wears the black body-paint of the
priest, his face-paint is alternately black and yellow, he has the warrior’s tousled hair,
the nasal rod with the square plaque falling [97]over the mouth, the forked heron-feather
adornment in his hair, and on his temple the smoking mirror. The foot, too, is torn off
and replaced by a smoking mirror—all symbolical of the “standard” character of the
god’s sable form. The Red Tezcatlipocâ represented in the upper portion of Borgia
(sheet 21) has a yellow face-painting striped with horizontal bands of red and his body-
paint is red. On the red bands crossing the face is seen the stellar eye. A brown fillet
encircles a red headdress, and the torn-off foot is also replaced by the smoking mirror.
On his back is seen the bundle of the merchant, surmounted by the arara bird, two
symbols which indicate his southern character. The representation of the Red
Tezcatlipocâ in the lower portion of sheet 21 is practically similar to this, save that he
wears feather balls and heron plumes in his headdress, is without the merchant’s pack,
and holds in one hand the jaguar-skin copal-bag of the priests and the smoking rubber
ball used as incense.

These forms of the god have been laid down in myth as distinctly separate deities,
especially in the Historia de los Mexicanos por sus Pinturas. 45

FESTIVALS

Toxcatl.—This, one of the most important of all the Mexican festivals, is described by
Sahagun substantially as follows: The fifth month called toxcatl and sometimes
tepopochuiliztli, was begun by the most solemn and famous feast of the year, in honour
of the principal Mexican god, a god known by a multitude of names and epithets,
among which were Tezcatlipocâ, Titlacaoan, Yautl, Telpuchtli, and Tlamatzincatl. A year
before this feast one of the most distinguished of the captives reserved for sacrifice
was chosen for his superior grace and personal appearance from among all his fellows,
and given in charge to the priestly functionaries called calpixques. These instructed him
with great diligence in all the arts pertaining to good breeding, [98]such as playing on
the flute, deportment, conversation, saluting those he happened to meet, the use of
straight cane tobacco-pipes and of flowers. He was attended upon by eight pages, who
were clad in the livery of the palace, and had perfect liberty to go where he pleased
night and day; while his food was so rich that, to guard against his growing too fat, it
was at times necessary to vary the diet by a purge of salt and water. Everywhere
honoured and adored as the living image and accredited representative of
Tezcatlipocâ, he went about playing on a small shrill clay flute or fife, and adorned with
rich and curious raiment furnished by the king, while all he met did him reverence,
kissing the earth. All his body and face was painted black, his long hair flowed to the
waist; his head was covered with white hens’ feathers stuck on with resin, and covered
with a garland of the flowers called izquixochitl, 46 while two strings of the same flowers
crossed his body in the fashion of cross-belts. Earrings of gold, a necklace of precious
stones, with a great dependent gem hanging to the breast, a lip-ornament (barbote) of
sea-shell, bracelets of gold above the elbow on each arm, and strings of gems called
macuextlu winding from wrist almost to elbow, were part of his ornaments. He was
covered with a rich, beautifully fringed mantle of netting, and bore on his shoulders
something like a purse made of white cloth of a span square, ornamented with tassels
and a fringe. A white maxtle of a span broad went about his loins, the two ends,
curiously wrought, falling in front almost to the knee. Little bells of gold hung upon his
feet, which were shod with painted sandals called ocelunacace.

(From Codex Borgia.) (From the Sahagun MS.)


(Pottery figure from the
Uhde Collection.)

TEZCATLIPOCÂ.

All this was the attire he wore from the beginning of his year of preparation; but twenty
days before the coming of the festival they changed his vestments, washed away the
paint or dye from his skin, and cut down his long hair to the length, and arranged it after
the fashion, of the hair of the captains, tying it up on the crown of the head with
feathers and fringe and two gold-buttoned tassels. At the same time they married to
him four damsels, who had [99]been pampered and educated for this purpose, and who
were surnamed respectively after the four goddesses, Xochiquetzal, Xilonen,
Atlantonan, and Uixtociuatl. Five days before the great day of the feast, the day of the
feast being counted one, all the people, high and low, the king it would appear being
alone excepted, went out to celebrate with the man-god a solemn banquet and dance,
in the ward called Tecanman; the fourth day before the feast the same was done in the
ward in which was guarded the statue of Tezcatlipocâ. The little hill or island called
Tepetzinco, rising out of the waters of the Lake of Mexico, was the scene of the next
day’s solemnities; which were renewed for the last time on the next day, or that
immediately preceding the great day, on another like island called Tepelpulco, or
Tepepulco. There, with the four women who had been given to him for his consolation,
the honoured victim was put into a covered canoe usually reserved for the sole use of
the king, and he was carried across the lake to a place called Tlapitzaoayan, near the
road that goes from Yztapalapan to Chalco, at a place where was a little hill called
Acaccuilpan, or Cabaltepec. Here left him the four beautiful girls whose society for
twenty days he had enjoyed, they returning to the capital with all the people. There
accompanied him only those eight attendants who had been with him all the year.
Almost alone, done with the joys of beauty, banquet, and dance, bearing a bundle of
his flutes, he walked to a little cu, some distance from the road mentioned above, and
about a league removed from the city. He marched up the temple steps; and as he
ascended he dashed down and broke on every step one of the flutes that he had been
accustomed to play on in the days of his prosperity. He reached the top, where he was
sacrificed. From the sacrificial stone his body was not hurled down the steps, but was
carried by four men down to the tzompantli, to the place of the spitting of heads.

TEZCATLIPOCÂ.

STONE ALTAR OF SKULLS TO TEZCATLIPOCÂ CARVED IN STONE.

(Museo Naçional, Mexico.)


In this feast of toxcatl, in the cu called Uitznahuac, where the image of Uitzilopochtli
was always kept, the priests made a bust of this god out of tzoalli dough, with pieces of
[100]mizquitl 47-wood inserted by way of bones. They decorated it with his ornaments;
putting on a jacket wrought over with human bones, a mantle of very thin nequen, and
another mantle called the Tlaquaquallo, covered with rich feathers, fitting the head
below and widening out above; in the middle of this stood up a little rod, also decorated
with feathers, and sticking into the top of the rod was a flint knife half covered with
blood. The image was set on a platform made of pieces of wood resembling snakes,
and so arranged that heads and tails alternated all the way round; the whole borne by
many captains and men of war. Before this image and platform a number of strong
youths carried an enormous sheet of paper resembling pasteboard, twenty fathoms
long, one fathom broad, and a little less than an inch thick; it was supported by spear-
shafts arranged in pairs of one shaft above and one below the paper, while persons on
either side of the paper held one of these pairs in one hand. When the procession, with
dancing and singing, reached the cu to be ascended, the platform was carefully and
cautiously hoisted up by cords attached to its four corners, the image was set on a
seat, and those who carried the paper rolled it up and set down the roll before the bust
of the god. It was sunset when the image was so set up; and the following morning
everyone offered food in his own house before the image of Uitzilopochtli, incensing
also such images of the other gods as he had, and then went to offer quails’ blood
before the image set up on the cu. The king began, wringing off the heads of four
quails; the priests offered next, then all the people; the whole multitude carrying clay
fire-pans and burning copal incense of every kind, after which everyone threw his live
coals on a great hearth in the temple yard. The virgins painted their faces, put on their
heads garlands of parched maize, with strings of the same across their breasts,
decorated their arms and legs with red feathers, and carried black paper flags stuck
into split canes. The flags of the daughters of the nobles were not of paper, but of a thin
cloth called canauac, painted [101]with vertical black stripes. These girls, joining hands,
danced round the great hearth, upon or over which, on an elevated place of some kind,
there danced, giving the time and step, two men, having each a kind of pine cage
covered with paper flags on his shoulders, the strap supporting which passed, not
across the forehead—the usual way for men to carry a burden—but across the chest,
as was the fashion with women. They bore shields of paper, crumpled up like great
flowers, their heads were adorned with white feathers, their lips and part of the face
were smeared with sugar-cane juice, which produced a peculiar effect over the black
with which their faces were always painted. They carried in their hands pieces of paper
called amasmaxtli 48 and sceptres of palm-wood tipped with a black flower and having in
the lower part a ball of black feathers. In dancing they used this sceptre like a staff, and
the part by which they grasped it was wrapped round with a paper painted with black
lines. The music for the dancers was supplied by a party of unseen musicians, who
occupied one of the temple buildings, where they sat, he that played the drum in the
centre, and the performers on the other instruments about him. The men and women
danced on till night, but the strictest order and decency were preserved, and any lewd
word or look brought down swift punishment from the appointed overseers.

This feast was closed by the death of a youth who had been during the past year
dedicated to and taken care of for Uitzilopochtli, resembling in this the victim of
Tezcatlipocâ, whose companion he had indeed been, but without receiving such high
honours. This Uitzilopochtli youth was entitled Ixteocalli, 49 or Tlacauepan, or
Teicauhtzin, 50 and was held to be the image and representative of the god. When the
day of his death came the priests decorated him with papers painted over with black
circles, and put a mitre of eagles’ feathers on his head, in the midst of whose plumes
was stuck a flint knife, stained half-way up with blood and adorned with red feathers.
Tied to his shoulders by strings [102]passing across the breast was a piece of very thin
cloth, about a span square, and over it hung a little bag. Over one of his arms was
thrown a wild beast’s skin, arranged somewhat like a maniple; bells of gold jingled at
his legs as he walked or danced. There were two peculiar things connected with the
death of this youth: first, he had absolute liberty of choice regarding the hour in which
he was to die; and, second, he was not extended upon any block or altar, but when he
wished he threw himself into the arms of the priests, and had his heart so cut out. His
head was then hacked off and spitted alongside that of the Tezcatlipocâ youth, of whom
we have spoken already. In this same day the priests made little marks on children,
cutting them, with thin stone knives, in the breast, stomach, wrists, and fleshy parts of
the arms; marks, as the Spanish priests considered, by which the devil should know his
own sheep.

Teotleco.—The movable feasts sacred to Tezcatlipocâ and alluded to in the list of his
festivals are only briefly mentioned by Sahagun, and do not appear to have been of
any particular importance. As regards the Teotleco Sahagun says: “The twelfth month
was called Teotleco, which signifies the arrival of the gods. A festival was celebrated in
honour of all the gods who were said to have gone to some country, I know not where.
On the last day of the month a greater one was held, because the gods had returned.

“On the fifteenth day of this month the young boys and the servitors decked all the
altars or oratories of the gods with boughs, as well those which were in the houses as
the images which were set up by the wayside and at the cross-roads. This work was
paid for in maize. Some received a basketful, and others only a few ears.

“On the eighteenth day the ever-youthful god Tlamatzincatl, or Titlacauan, arrived. It
was said that he marched better and arrived the first because he was young and
strong. Food was offered him in his temple on that night. Everyone drank, ate, and
made merry; the old people especially celebrated the arrival of the god by drinking
wine, and it was alleged that his feet were washed by these rejoicings. [103]The last day
of the month was marked by a great festival, on account of the belief that the whole of
the gods arrived at that time. On the preceding night a quantity of flour was kneaded on
a carpet into the shape of a cheese, it being supposed that the gods would leave a
footprint thereon as a sign of their return. The chief attendant watched all night, going
to and fro to see if the impression appeared. When he at last saw it he called out, ‘The
master has arrived,’ and at once the priests of the temple began to sound the horns,
trumpets, and other musical instruments used by them. Upon hearing this noise
everyone ran forthwith to offer food in all the temples or oratories, and gave themselves
up to renewed rejoicings, to wash the feet of the gods, as we have already described.

“The next day the aged gods were said to come last, because they walked more slowly
on account of their age. On that day several captives were doomed to be burnt alive. A
great brazier was prepared; young men disguised as monsters danced round about it,
and while dancing, hurled the unhappy victims into the fire, in the manner already
explained. Other ceremonies took place which will be described in the account of this
festival.”

MYTHS

Sahagun says of Tezcatlipocâ that he was invisible and was able to penetrate into all
places, heaven, earth, and hell. The Mexicans, he says, believed that he wandered
over the earth stirring up strife and war, and setting men against one another. He also
remarks that he was the true giver of prosperity, and extremely capricious. 51

Acosta calls him the god of drought, famine, barrenness, and pestilence. 52

Clavigero alludes to him as the chief of the gods worshipped in Mexico, the god of
providence, the soul of the world, the creator of heaven and earth and master of all
things. “They represented him as young, to denote that no length of years ever
diminished his power. They believed [104]that he rewarded with various benefits the just,
and punished the wicked with diseases and other afflictions.” 53

The interpreter of Codex Telleriano-Remensis states that “Tezcatlipocâ is he who


appeared to the nation on the mountain of the mirror, as they say, and is he who
tempted Quetzalcoatl the penitent.” Elsewhere he says: “They do not here paint
Tezcatlipocâ with a foot formed of a serpent, since they say that this festival
[panquetzaliztli] relates to a time previous to his sinning while still in heaven, and that
hence happened the war in heaven, from whence wars sprung below.”

The interpreter of Codex Vaticanus A. says of him: “Tezcatlipocâ, here represented,


was one of their most potent gods. They say that he appeared in that country on the
top of a mountain called Tezcatepu, which signifies the mountain of mirrors.” Later on
he remarks that the god was sometimes painted with the feet of a man and of a cock,
“as they say his name bears allusion to this circumstance. He is clothed with a fowl,
which seems to cry in laughing accents, and when it crows, Oa, Oa, Oa, they say that it
deceived the “first woman, who committed sin, and accordingly they place him near the
goddess of pollution.”

A report on the Huaxtec territory, dated 1579, states that: “They relate another fable,
that they had two other effigies as gods, one called Ometochtli, who is the god of wine,
the other Tezcatlipocâ, which is the name of the most exalted idol worshipped by them,
and with these they had painted the figure of a woman named Hueytonantzin, that is
‘our great mother,’ because they said that she was the mother of all these gods or
demons. And those four above-mentioned male demons, they related, had killed this
great mother, founding with her the institution of human sacrifice, and taking her heart
out of her breast, and presenting it to the sun. Similarly, they related that the idol
Tezcatlipocâ had killed the god of wine with his consent and concurrence, giving out
that in this way he gave eternal life, and that if he did not die, all persons drinking wine
must die; but that the [105]death of this Ometochtli was only the sleep of one drunk, that
he afterwards recovered, and again became fresh and well.”

Tezcatlipocâ, it will be remembered, is alluded to in the cosmogonic myths of Mendieta


and Sahagun, already related in the chapter on Cosmogony. The Historia de los
Mexicanos por sus Pinturas refers to him as the creator, says that “he made the sun to
shine,” and states that he was the constellation Ursa Major, the Great Bear, which
“sank in the water.” He also made the Tazcaquavlt, or “tree of the mirror,” fashioned
four hundred men and a hundred women as food for the sun, and, along with
Quetzalcoatl, constructed “the road in the heavens, the Milky Way.”

Sahagun states 54 that after Tezcatlipocâ had succeeded in driving Quetzalcoatl from
the country, “he proceeded further guilefully to kill many Toltecs and to ally himself by
marriage with Vemac or Uemac, who was the temporal lord of the Toltecs, even as
Quetzalcoatl was the spiritual ruler of that people. To accomplish these things
Tezcatlipocâ took the appearance of a poor foreigner and presented himself naked, as
was the custom of such people, in the market-place of Tulla, selling green chilli pepper.
Now the palace of Vemac, the great king, overlooked the market-place, and he had an
only daughter, and the girl, looking by chance among the buyers and sellers, saw the
disguised god. She was smitten through with love of him, and she began to sicken.
Vemac heard of her sickness, and he inquired of the women who guarded her as to
what ailed his daughter. They told him as best they could, how for the love of a peddler
of pepper, named Toveyo, the princess had lain down to die. The king immediately sent
a crier upon the mountain Tzatzitepec to make this proclamation: ‘O Toltecs, seek me
out Toveyo that goes about selling green pepper, let him be brought before me.’ So the
people sought everywhere for the pepper vendor, but he was nowhere to be found.
Then after they could not find him, he appeared [106]of his own accord one day, at his
old place and trade in the market. He was brought before the king, who said to him:
‘Where dost thou belong to?’ and Toveyo answered, ‘I am a foreigner, come here to sell
my green pepper.’ ‘Why dost thou delay to cover thyself with breeches and a blanket?’
said Vemac. Toveyo answered that in his country such things were not in the fashion.
Vemac continued: ‘My daughter longs after thee, not willing to be comforted by any
Toltec. She is sick of love and thou must heal her.’ But Toveyo replied: ‘This thing can
in no wise be; kill me first; I desire to die, not being worthy to hear these words, who
get my living by selling green pepper.’ ‘I tell thee,’ said the king, ‘that thou must heal my
daughter of this her sickness; fear not.’ Then they took the cunning god and washed
him, and cut his hair, and dyed all his body and put breeches on him and a blanket; and
the king Vemac said, ‘Get thee in and see my daughter, there, where they guard her.’
Then the young man went in and he remained with the princess and she became
sound and well; thus Toveyo became the son-in-law of the king of Tulla.

“Then, behold, all the Toltecs, being filled with jealousy and offended, spake injurious
and insulting words against King Vemac, saying among themselves, ‘Of all the Toltecs
can there not be found a man, that this Vemac marries his daughter to a peddler?’ Now
when the king heard all the injurious and insulting words that the people spake against
him he was moved, and he spoke to the people saying, ‘Come hither, behold I have
heard all these things that ye say against me in the matter of my son-in-law Toveyo;
dissimulate then; take him deceitfully with you to the war of Cacatepec and Coatepec,
and let the enemy kill him there.’ Having heard these words, the Toltecs armed
themselves, and collected a multitude and went to the war, bringing Toveyo along.
Arrived where the fighting was to take place, they hid him with the lame and the dwarfs,
charging them, as the custom was in such cases, to watch for the enemy, while the
soldiers went on to the attack. The battle began. The Toltecs at once gave way,
treacherously [107]and guilefully deserting Toveyo and the cripples. Leaving them to be
slaughtered at their post, they returned to Tulla and told the king how they had left
Toveyo and his companions alone in the hands of the enemy. When the king heard the
treason he was glad, thinking Toveyo dead, for he was ashamed of having him for a
son-in-law. Affairs had gone otherwise, however, with Toveyo from what the plotters
supposed. On the approach of the hostile army he consoled his deformed companions,
saying: ‘Fear nothing; the enemy come against us, but I know that I shall kill them all.’
Then he rose up and went forward against them, against the men of Coatepec and
Cacatepec. He put them to flight and slew of them without number. When this came to
the ears of Vemac it weighed upon and terrified him exceedingly. He said to his Toltecs,
‘Let us now go and receive my son-in-law.’ So they all went out with King Vemac to
receive Toveyo, bearing the arms and devices called quetzalapanecayutl, and the
shields called xiuhchimali. 55 They gave these things to Toveyo, and he and his
comrades received them with dancing and the music of flutes, with triumph and
rejoicing. Furthermore, on reaching the palace of the king, plumes were put upon the
heads of the conquerors, and all the body of each of them was stained yellow, and all
the face red. This was the customary reward of those that came back victorious from
war. And King Vemac said to his son-in-law: ‘I am now satisfied with what thou hast
done, and the Toltecs are satisfied; thou hast dealt very well with our enemies, rest and
take thine ease.’ But Toveyo held his peace.

“And after this, Toveyo adorned all his body with the rich feathers called tocivitl, and
commanded the Toltecs to gather together for a festival, and sent a crier up to the top
of the mountain Tzatzitepec, to call in the strangers and the people afar off to dance
and to feast. A numberless multitude gathered to Tulla. When they were all gathered,
Toveyo led them out, young men and girls, to a place called Texcalapa, where he
himself began and led the dancing, playing [108]on a drum. He sang too, singing each
verse to the dancers, who sang it after him, though they knew not the song beforehand.
Then was to be seen a marvellous and terrible thing. A panic seized the Toltecs. There
was a gorge or ravine there, with a river rushing through it called the Texcaltlauhco. A
stone bridge led over the river. Toveyo broke down this bridge as the people fled. He
saw them tread and crush each other down, under-foot, and over into the abyss. They
that fell were turned into rocks and stones; as for those that escaped, they did not see
nor think that it was Toveyo and his sorceries had wrought this great destruction; they
were blinded by the witchcraft of the god, and out of their senses like drunken men.

“Tezcatlipocâ then proceeded to hatch further evil against the Toltecs. He took the
appearance of a certain valiant man called Teguioa, and commanded a crier to
summon all the inhabitants of Tulla and its neighbourhood to come and help at a
certain piece of work in a certain flower-garden (said to have been a garden belonging
to Quetzalcoatl). All the people gathered to the work, whereupon the disguised god fell
upon them, knocking them on the head with a hoe. Those that escaped the hoe were
trodden down and killed by their fellows in attempting to escape. A countless number
was slain. Every man that had come to the work was left lying dead among the trodden
flowers.

“And after this Tezcatlipocâ wrought another witchcraft against the Toltecs. He called
himself Tlacavepan, or Acexcoch, and came and sat down in the midst of the market-
place of Tulla having a little manikin (said to have been Uitzilopochtli) dancing upon his
hand. There was an instant uproar of all the buyers and sellers and a rush to see the
miracle. The people crushed and trod each other down, so that many were killed there;
and all this happened many times. At last the god-sorcerer cried out on one such
occasion: ‘What is this? Do you not see that you are befooled by us? Stone and kill us.’
So the people took up stones and killed the said sorcerer and his little dancing manikin.
But when the body of the sorcerer had lain in [109]the market-place for some time it
began to stink and to taint the air, and the wind of it poisoned many. Then the dead
sorcerer spake again, saying: ‘Cast this body outside the town, for many Toltecs die
because of it.’ So they prepared to cast out the body, and fastened ropes thereto and
pulled. But the ill-smelling corpse was so heavy that they could not move it. Then a
crier made a proclamation, saying: ‘Come, all ye Toltecs, and bring ropes with you, that
we may drag out and get rid of this pestilential carcass.’ All came accordingly, bringing
ropes, and the ropes were fastened to the body and all pulled. It was utterly in vain.
Rope after rope broke with a sudden snap, and those that dragged on a rope fell and
were killed when it broke. Then the dead wizard looked up and said; ‘O Toltecs, a verse
of song is needed.’ And he himself gave them a verse. They repeated the verse after
him, and, singing it, pulled all together, so that with shouts they hauled the body out of
the city, though still not without many ropes breaking and many persons being killed as
before. All this being over, those Toltecs that remained unhurt returned every man to
his place, not remembering anything of what had happened, for they were all as
drunken.

“Other signs and wonders were wrought by Tezcatlipocâ in his rôle of sorcerer. A white
bird called Iztac cuixtli was clearly seen flying over Tulla, transfixed with a dart. At night
also, the sierra called Zacatepec burned, and the flames were seen from afar. All the
people were stirred up and affrighted, saying one to another, ‘O Toltecs, it is all over
with us now; the time of the end of Tulla is come; alas for us, whither shall we go?’

“Then Tezcatlipocâ wrought another evil upon the Toltecs; he rained down stones upon
them. There fell also, at the same time, a great stone from heaven called Techcatl; and
when it fell the god-sorcerer took the appearance of an old woman, and went about
selling little banners in a place called Chapultepec Cuitlapilco, otherwise named
Uetzinco. Many then became mad and bought of these banners and went to the place
where was the stone Techcatl, and there [110]got themselves killed; and no one was
found to say so much as, ‘What is this that happens to us?’ They were all mad.

“Another woe Tezcatlipocâ brought upon the Toltecs. All their victuals suddenly became
sour, and no one was able to eat of them. The old woman, above mentioned, took up
then her abode in a place called Xochitla, and began to roast maize: and the odour of
the roasted maize reached all the cities round about. The starving people set out
immediately, and with one accord, to go where the old woman was. They reached her
instantly, for here it may be again said, that the Toltecs were exceedingly light of foot,
and arrived always immediately whithersoever they wished to go. As for the Toltecs that
gathered to the mock sorceress, not one of them escaped. She killed them every one.”

These feats of Tezcatlipocâ against the Toltecs seem to have reference to the various
species of charm wielded by the enchanter; the love-charm, the charm by music, by
disease, by destruction of victuals. The rain of stone signified barrenness, drought,
which was implied by the nature of the god, the deity of obsidian and of tempests.
For other myths regarding Tezcatlipocâ see the chapter on Cosmogony.

NATURE AND STATUS

In my opinion the early significance of Tezcatlipocâ arises out of his connection with
obsidian. This stone had an especial sanctity for the Mexicans, as it provided the
sacrificial knives employed by the priests, and we possess good evidence that stone in
its fetish form was worshipped even so late as the eighteenth century by the Nahuatl-
speaking Chotas, who comprised it in a trinity with the Dawn and the Serpent. 56 From a
passage in Acosta 57 we are justified in assuming that Tezcatlipocâ’s idol was of
obsidian, and, like the Quiche god Tohil, mentioned in the Popol Vuh, he wore sandals
of obsidian, as is witnessed by one of his representations in Codex Borbonicus, where
his footgear is painted with the zigzag line of the obsidian snake. [111]

Tezcatlipocâ was unquestionably the god of the itztli (obsidian) stone, and Seler 58 has
identified him with Iztli, the stone-knife god, the second of the lords of the night. In
certain codices, too, he is represented as having such a knife in place of a foot, and we
know that it was a fairly common practice of the Mexican artists to indicate the name or
race of an individual by drawing one of his feet in a hieroglyphical manner. 59 I believe,
too, that the net-like garment worn at times by the god above his other attire is an
adaptation of the mesh-bag in which Mexican hunters carried flints for use as spear-
and arrow-heads.

This, as well as the fact that he was the god of the sharp-cutting obsidian from which
such weapons were made, caused him to be regarded as patron deity of the wild
hunting Chichimecs of the northern steppes, a connection which is eloquent of his
erstwhile primitive character. It is clear, too, that Chalchiuhtotolin, the jewelled fowl,
which is ruler of the eighteenth day-sign, tecpatl (obsidian knife), is merely a variant of
Tezcatlipocâ. 60 [112]

But another important link connects Tezcatlipocâ with obsidian. Bernal Diaz states that
they called this “Tezcat.” From it mirrors were manufactured as divinatory media by the
wizard. Sahagun says 61 that it was known as aitztli (water obsidian), probably because
of the high polish of which it was capable. Another such stone he mentions was called
tepochtli, which I would translate “wizard stone,” and from which I think, by a process of
etymological confusion, Tezcatlipocâ received one of his minor names, Telpochtli, “the
youth.” The name of the god means “Smoking Mirror,” and Acosta 62 says that the
Mexicans called Tezcatlipocâ’s mirror irlacheaya (an obvious error for tlachialoni) “his
glass to look in,” otherwise the mirror or scrying-stone in which he was able to witness
the doings of mankind. It is possible that the “smoke” which was said to rise from this
mirror symbolized the haziness which is supposed to cloud the surface of a divinatory
glass prior to the phenomenon of vision therein.

Thus from the shape beheld in the seer’s mirror, Tezcatlipocâ came to be regarded as
the seer. That into which the wizard gazed became so closely identified with sorcery as
to be thought of as wizard-like itself; for Tezcatlipocâ is, of all Mexican deities, the one
most nearly connected with the wizard’s art. He is par excellence the nocturnal god
who haunts the crossways and appears in a myriad phantom guises to the night-bound
wayfarer. “These,” says Sahagun, “were masks that Tezcatlipocâ assumed to frighten
the people.”

He wears the symbol of night upon his forehead; he is the moon, ruler of the night, the
wizard who veils himself behind the clouds; he bears the severed arm of a woman who
has died in childbed, as a magical instrument, as did the naualli of old Mexico. From
him all ominous and uncanny sounds proceed: the howl of the jaguar (in which we
perceive Tezcatlipocâ as the wizard metamorphosed [113]into the wer-animal), and the
foreboding cry of the uactli bird, the voc, the bird of Hurakan in the Popol Vuh.

Tezcatlipocâ was undoubtedly connected with the wind, and this leads me to suspect
that in the course of his evolution he came to be thought of as among that class of
magical stones which in some mysterious manner is considered capable of raising a
tempest under the spell of the sorcerer. 63 Of such a belief world-wide examples exist. In
the Irish island of Fladdahuan such a stone was anointed when the fisher desired a
wind 64 and was kept in wool wrappings. A piece of pumice-stone drifted to Puka-Puka,
says Lang, 65 and was regarded as a god of winds and waves, to which offerings were
made during hurricanes. Tezcatlipocâ is none other than the original “hurricane,” for he
has been identified with the Hurakan of the Quiches of Guatemala alluded to in the
Popol Vuh, from whose name the meteorological expression has been borrowed.

Whether or not he came to be looked upon as the wind of night which ravined through
the empty streets and deserted countryside by virtue of the train of thought suggested
above, many aspects of Tezcatlipocâ are eloquent of his boreal attributes. Thus, he is
invisible and capricious, the object of mistrust among the people, who discerned in
tempestuous weather a manifestation of his freakish bad temper. The myth in which he
was described as pursuing Quetzalcoatl in tiger-form will, in the section which deals
with that god, be indicated as an allegory of the clashing of the hurricane with the rain-
bringing trade-wind. Lastly, as patron of war, of the warrior’s club and dance-house, he
is, as the boisterous storm, emblematic of strife and discord. Seats of stone over-
arched with green branches were provided for him throughout the city so that he might
rest from his wanderings if he thought good. [114]

In the Aztec mind stone was symbolic of sin. Thus Tezcatlipocâ in his variant,
Itzlacoliuhqui, is the just avenger, who punishes evil swiftly and terribly, for obsidian as
the sacrificial knife was the instrument of justice. 66 The coldness of stone, its hardness
and dryness, seem also to have given rise to the conception of him as god of the
Toxcatl festival in the fifth month of the year, the dry season, when the sun stood at the
zenith above Tenochtitlan. Thus, as the prayers to him eloquently affirm, he was the
god of drought, of sereness, and barrenness.

In common with the majority of the greater Mexican deities, Tezcatlipocâ had a stellar
connection. He was one of the Tzitzimimê who had fallen from heaven, and the Historia
de los Mexicanos por sus Pinturas remarks of him, “the constellation of the Great Bear
descends to the water because it is Tezcatlipocâ, who has his seat there,” thus also
indicating that he ruled the northern quarter, out of which, it was considered, no good
thing might come. His Tzitzimimê shape appears to have been the spider. In American-
Indian myth the stars are frequently regarded as having spider form, and especially so
in Mexican myth. In several of the codices, notably in Codex Borbonicus, the
Tzitzimimê or star-demons are represented in insect shape. Thus, Tezcatlipocâ, when
he descended from heaven to harass Quetzalcoatl, did so by means of a spider’s web,
so that we are justified in regarding the spider as his stellar form.

The origin of his conception as the sun of the north and as the setting sun seems
reasonably clear and is secondary in character. As the sun sinks in the west its brilliant
gold turns to a glassy red, reminiscent of the dull reflex of light in a surface of polished
obsidian. The mirror held by Tezcatlipocâ, with its fringe of feathers, obviously
represents the sun of evening. But he is also to be thought of as the torrid and blazing
orb of the dry season, scorching and merciless.

I regard his several coloured forms as symbolic of various [115]kinds of weather. Thus,
in his black form he appears to represent the rainy season; in his red, the torrid and dry
period of the year; in his white, cold and frost; and in his striped painting, the
embodiment of fair weather. Thus Tezcatlipocâ is the atmospheric god par excellence,
ruler of all meteorological conditions. In the prayers offered up to him it is frequently
stated that he may, if he so chooses, send rain and plenty, and this aspect of him
seems to account for his variously coloured disguises. That these were, indeed,
regarded as practically separate divine forms is clear from the first chapter of the
Historia de los Mexicanos por sus Pinturas, which alludes to the Black and Red
Tezcatlipocâ as two entirely different gods.

Tezcatlipocâ, at the period of the Conquest, had developed attributes of a more lofty
kind than any of those already described. Like Quetzalcoatl, and because he was a
god of the wind or atmosphere, he came to be regarded as the personification of the
breath of life. In the mind of savage man the wind is usually the giver of breath, the
great store-house of respiration, the source of immediate life. In many mythologies the
name of the principal deity is synonymous with that for wind, and in others the words
“soul” and “breath” have a common origin. It has been suggested that the Hebrew
Jahveh (the archaic form of Jehovah) is connected with the Arabic hawah, to blow or
breathe, and that Jahveh was originally a wind or tempest god.

Our word “spiritual” is derived from the Latin spirare, to blow; the Latin animus, “spirit,”
is the same word as the Greek anemos, “wind,” and psukhe has a similar origin. All are
directly evolved from verbal roots expressing the motion of the wind or the breath. The
Hebrew word ruah is equivalent to both “wind” and “spirit,” as is the Egyptian kneph. If
we turn to the American mythologies, nija in the language of the Dakota means
“breath,” or “life”; in Netela piuts is “life,” “breath,” and “soul”; the Yakuna language of
Oregon has wkrisha, “wind,” wkrish­mit, “life.” The Creeks applied to their supreme deity
the [116]name Esaugetuh Emissee, Master of Breath, 67 and the original name for God in
Choctaw was Hustoli, the Storm Wind. “In the identity of wind with breath, of breath
with life, of life with soul, of soul with God, lies the far deeper and truer reason,” says
Brinton, “of the prominence given to wind-gods in many mythologies.” 68

But although Tezcatlipocâ was the Giver of Life, he was also regarded as a deity with
power to take it away. In fact at times he appeared as an inexorable death-dealer, and
in this guise he was named Nezahualpilli (“The Hungry Chief”) and Yaotzin (“The
Enemy”). But he was also known as Telpochtli (“The Youthful Warrior”), from the fact
that his reserve of strength, his vital force, never grew less and was boisterously
apparent, as in the tempest. As the wind at night rushes through the roads with more
seeming violence than it does by day, so was Tezcatlipocâ pictured in the Aztec
consciousness as rioting along the highways in search of slaughter. Indeed, seats or
benches of stone, shaped like those used by the chiefs of the Mexican towns, were
placed at intervals on the roads for his use, and here he was supposed to lurk,
concealed by the green boughs which surrounded them, in wait for his victims. Should
anyone grapple with and overcome him, he might crave whatsoever boon he desired,
with the surety of its being granted. The worship of Tezcatlipocâ previous to the
Conquest had so advanced, and so powerful had his cult become, that it would appear
as if the movement would ultimately have led to a monotheism or worship of one god
equivalent to that of the cult of Jahveh, the God of the Old Testament among the
ancient Hebrews. To his priestly caste is credited the invention of many of the usages
of civilized life, and it succeeded in making his worship universal. The Nahua people
regarded the other gods as objects of special devotion, but the worship of Tezcatlipocâ
was general. [117]

[Contents]
QUETZALCOATL = “FEATHERED SERPENT”

Area of Worship: The Plateau of Anahuac.


Minor Names:
Chicunaui eecatl—“Nine Wind.”
Ce acatl—“One Reed.”
Relationship: Son of Iztacmixcoatl and Chimalman or Xochiquetzal; one of the
Tzitzimimê.
Calendar Place:
Ruler of the second day-count, eecatl.
Ruler of the second week, ce ocelotl.
Ninth of the thirteen day-lords.
Festivals:
Ce acatl (movable feast).
Atlacahualco.
Compass Direction: East.

ASPECT AND INSIGNIA

General.—The insignia of Quetzalcoatl is fairly constant in its appearance. He usually


wears the Huaxtec cone-shaped hat painted in the design of the jaguar-skin, which is
occasionally divided vertically into a black or blue and a red field, having an eye in the
middle. The hair is bound by a leather strap set with jewels, which has a conventional
bird’s head on the front, and in Codex Borgia consistently shows a black, stepped
pattern on a white ground. Elsewhere a bow with rounded ends takes the place of this
strap, but in Borgia (sheet 62) the hair is bound up with two intertwined snakes. At the
back of the neck a fan-shaped nape-ornament is usually seen, consisting of black
feathers, from which rise the red plumes of the quetzal bird, and it seems, from the
account of the costume sent to Cortéz by Motecuhzoma, that this nape-appendage
was made from grouse-feathers, although the Spanish account states that they
belonged to the crow. The god usually wears white ear-pendants of hook-like shape,
which, Sahagun states, were made of gold. The necklace is of spirally voluted snail-
shells, and on the breast is worn a large ornament, also sliced from a shell. The ends
of the loin-cloth are rounded off and are generally painted in two colours—brown, the
colour [118]of the jaguar-skin, and white or red. The god’s atlatl, or spear-thrower, is
painted with the stellar design of white circles on a black ground, and in his headdress
is stuck the agave-leaf spike and the bone dagger, the implements of penance and
mortification. The body-paint is frequently black, like that of the priests. Most of these
insignia are of Huaxtec origin and show that Quetzalcoatl was usually associated with
this coastal people. The snail-shell ornament on the breast, the hook-shaped ear-
pendant, the fan-shaped nape-ornament, and the cone-shaped cap, were undoubtedly
of Huaxtec origin, and such objects have been taken from Huaxtec graves and are
found represented on vases and jugs from the State of Hidalgo. In many
representations of him the god is seen wearing a long-snouted mask, usually painted a
bright red, through which he was supposed to expel the wind in his guise of Eecatl, the
Wind-god. This mask is frequently fringed with a beard.

FORMS OF QUETZALCOATL.

Quetzalcoatl (right) and Tlauizcalpantecutli. (Codex Borgia, sheet 19.)

Codex Vaticanus B.—Sheet 75: Quetzalcoatl’s body-paint is a dark colour, and in his
hair he wears unspun cotton, as does Tlazoltcotl. Sheet 76: Here his face is painted
black and he wears the fillet with the step-pattern and the two-coloured cap, and in his
hair are stuck the instruments of mortification. He holds in his hand a snake, which is to
be regarded as the agricultural implement with which he tills the ground.

Codex Borgia.—Sheet 73: In this place he is set back to back with the Death-god and
is surrounded by the twenty day-signs. The body-paint is light blue, and the anterior
part of the face has the stellar painting of white circles on a black ground. His conical
cap has the parti-coloured painting and the cross, the symbol of the four winds, in the
middle. On his breast he wears the snail-shell and in his hand a blue staff. His wind-
mask is entirely covered with stellar and lunar emblems. His rattle-staff is light blue, in
contradistinction to that of the Death-god, which is sprinkled with blood. Sheet 56: Here
he is equipped with the hoe and wears the body-paint of a priest, a necklace of jaguar-
skin and teeth, the conical bi-coloured cap, the [119]stepped fillet with conventional
bird’s head in front, and the bearded face-mask. Stellar symbols and feather-balls dot
his dress and headdress. He stands back to back with the Death-god, and it is clear
that here he is intended to represent the heavenly Quetzalcoatl, the giver of breath and
life. On sheet 72 we see him as a priest surrounded by day-signs and implements of
mortification. Sheet 19: As represented in this sheet he stands opposite the Death-god.
He wears a dark-coloured garment, and what can be seen of his face is painted black,
with a spiral pattern. His mantle bears the cross-hatchings indicative of rain or water
and is ornamented with feather balls. The red wind-mask protrudes beneath a parti-
coloured cap with stellar eyes, and a fillet with step-pattern and conventional bird’s
head, and he wears the snail-shell breast ornament and carries the implements of
mortification. Sheet 16: On the lower right-hand corner of this sheet he is depicted in a
precisely similar manner.

FORMS OF QUETZALCOATL.

Quetzalcoatl (right) and the Death-god. (Codex Vaticanus, 3773, sheet 76.)

Quetzalcoatl’s Dress sent to Cortéz.—When Cortéz landed at Vera Cruz,


Motecuhzoma, believing him to be the god Quetzalcoatl returned, sent him “the dress
that was appropriate to him.” 69 This consisted of four costumes, that of Quetzalcoatl
proper, and those of Tezcatlipocâ, Tlaloc, and Xiuhtecutli, the Fire-god, who were
regarded as the four deities dominant in the four quarters of the heavens, and had in
the higher theology become fused in the conception of Quetzalcoatl, or were regarded
as variants of him. The Quetzalcoatl dress proper is said by Sahagun to have consisted
of the turquoise snake-mask, now to be seen in the British Museum, and which can be
easily identified by the folds of the snake’s body forming the eyebrows, the quetzal-
feather adornment, and the turquoise throwing-stick, shaped in the form of a snake. It
seems probable, however, that this dress, although it is described as that of
Quetzalcoatl, was that associated with the Fire-god.

Codex Magliabecchiano.—Sheet 89: Quetzalcoatl is here represented in a dancing


attitude. He wears the Huaxtec [120]hat made of jaguar-skin, the shield with the snail-
shell ornament, which is also reproduced on his breast, and the yellow and red face-
painting. The bone “reed” for piercing the tongue is stuck in his headgear, and from it
depend balls of cotton. He carries an atlatl, or spear-thrower, symbolic of rain or wind,
and similar in motif to the nose-ornament of the Maya God B. His mantle is cross-
hatched to symbolize rain or water and is decorated with red bows. He wears anklets of
jaguar-skin, and a panache of green and yellow feathers.

Quetzalcoatl. (From the


Sahagun MS.)
Pottery figure of Quetzalcoatl from
Tezcuco.

FORMS OF QUETZALCOATL.

Sahagun MS. (Biblioteca del Palacio).—In the illustration which accompanies his
description in this MS. he wears a pointed cap of jaguar-skin, surmounted by quetzal-
plumes. The face and body are painted black with soot, and a curved band falls from
beneath the hat to the neck. He wears the golden “water-snake” collar, and on his back
the wing of the red guacamayo. Over the hips is slung a cloth with a red border. He
wears white sandals, and pieces of jaguar-skin are fastened over the foot. On his
shield he has the shell which is typical of him, and in his hand a staff with a motif like
that of the nose of the Maya God B. Sahagun says of him: “His image was always in a
recumbent position and covered with blankets. The face of it was very ugly, the head
large and furnished with a long beard.” 70

Torquemada states that Quetzalcoatl was a white man, large-bodied, broad-browed,


great-eyed, with long black hair and a beard heavy and rounded. 71

Acosta says of Quetzalcoatl’s image at Cholula: “They called it Quetzallcoalt. This idoll
was in a great place in a temple very high. It had about it gold, silver, jewels, very rich
feathers, and habits of divers colours. It had the forme of a man, but the visage of a
little bird with a red bill, and above a combe full of warts, having ranks of teeth and the
tongue hanging out. It carried upon the head a pointed myter of painted paper, a sithe
in the hand, and many toyes of gold on the legs, with a thousand other foolish
inventions, whereof all had their significations.” 72 [121]

Elsewhere Acosta says: “The greatest idoll of all their gods was called
Quezcalcovately.… He never ware but one garment of cotton, which was white, narrow
and long, and upon that a mantle beset with certain red crosses. They have certain
green stones which were his, and those they keep for relickes. One of them is like an
ape’s head.”

Anales de Quauhtitlan.—In this work Quetzalcoatl is described as wearing the


turquoise snake-mask and the quetzal-feather ornament—that is, the decorations of
the Fire-god: “Lastly in the year one reed they say, when he had arrived on the shore of
the sea, then he began to weep and put off the garb with which he was arrayed, his
quetzal-feather ornament, his turquoise mask.”

QUETZALCOATL.

(From a wall-painting at Mitla.)


TONACATECUTLI-TONACACIUATL.

(From Codex Borgia.)

STATUARY

A statuette of the god from the Valley of Mexico exhibits him in a high cap, ornamented
round the lower portion with a serpentine motif, and wearing the sliced snail-shell
dress-ornament. A caryatid found in the Calle de las Escalerillas, Mexico City, on the
16th of October 1900, represents him with a long, pointed beard, which might,
however, be interpreted as the mouth-mask of the Wind-god lowered down to show the
upper part of the face more clearly, and it would seem from this statue that the beard
with which Quetzalcoatl is represented in some places in Mexican art is nothing more
or less than the mouth-mask pushed down over the chin and neck, although it must be
admitted that his mask is frequently depicted with what is undoubtedly a beard. A relief
excavated at the Castillo de Teayo shows Quetzalcoatl wearing the feathered-serpent
helmet-mask, which in this representation is most elaborate, and the sliced snail-shell
dress-ornament. Two figures of Quetzalcoatl found near Texcuco exhibit considerable
differentiation from other forms. In both he is seated on the top of a teocalli or temple,
and behind him is seen the solar emblem, represented as a large, flaming disc. He
wears a high cap which reminds one of the crown of Upper Egypt, as seen in Egyptian
representations, except that it is flanked on either side by two large [122]studs or knobs
and is surrounded at the base by the serpent-motif, as in the specimen from the Valley
of Mexico. He also wears his usual breast-ornament. In a round sculpture found at
Puebla we perhaps see Quetzalcoatl as a butterfly, and can only identify this figure as
the god because of the wind-mask it wears.
WALL-PAINTINGS

In several of the wall-paintings at Mitla, and especially in those on the north side of
Palace I, Quetzalcoatl is depicted as wearing the insignia usually connected with him in
Mexico. In one of these he wears the Huaxtec cap with jaguar-skin markings, having
the sacrificial implements stuck in it, and the wind-mouth mask, with beard. The snail-
shell ornament adorns his shield. In another the facial insignia is less easily seen, but
the large nape-fan with which he is frequently adorned is well depicted. Immediately
behind this is a figure, which, though partially destroyed, is still interesting because of
its high degree of conventionality. We have here the cap and panache of Quetzalcoatl,
together with the strip running from brow to eye and from eye to jaw, which is part of
the face-painting of the Moon-god. Moreover, in the corner we have the symbol of the
moon, a pot-shaped bone, so that here, I think, we have a symbol of Quetzalcoatl as
the Moon-god. In the preceding figure, too, we have also the lunar emblem, in this
place in shape like the nose-plug of the octli-gods, but containing the stellar eye, and
flanked by balls of feather-down. It would thus seem that the symbol has some
reference to Quetzalcoatl in his variant of the planet Venus. Moreover the eye appears
as gouged out. This eye-gouging is seen in the Maya Books of Chilan Balam, in the
case of the god Itzamná. These two latter paintings, Seler thinks, are symbolic of the
Uiyatao, or the high-priests of Mitla, who were regarded as incarnations of
Quetzalcoatl. 73 [123]

MYTHS

The myths concerning Quetzalcoatl are numerous and conflicting. In the first place I
shall provide a careful précis of the more important, their prolixity rendering full
quotation impossible.

Sahagun’s account of Quetzalcoatl may be summarized as follows: The arts had their
inception with Quetzalcoatl. His houses were made of chalchiuites, silver, white, and
red shells, and rich feathers. His folk were nimble and swift in passage from one place
to another, and were called tlanquace­milhiyme. 74 He gave his commands to the people
for a hundred leagues round by means of a crier stationed on the mountain
Tzotzitepetl. 75 He had wealth in abundance, provision in plenty, and in his time maize
was so large in the head that a man might not carry more than one stalk in his clasped
arms. Pumpkins were in circumference as great as a man is high, and the stalks of the
wild amaranth grew like trees. Cotton grew in all colours—red, scarlet, yellow, violet,
white, green, blue, black, grey, orange, and tawny. In the city of Tollan, where
Quetzalcoatl dwelt, were many birds of rich plumage and sweet song. The servants of
Quetzalcoatl were wealthy and had abundance of all things, and food was plentiful with
them. Their master did penance by pricking his legs and drawing blood with the spines
of the maguey and by washing at midnight in a fountain. But sorcerers came against
Quetzalcoatl and his people, the Toltecs, and these, we are told, were the gods
Tezcatlipocâ, Uitzilopochtli, and Tlacuepan. Tezcatlipocâ visited the house of
Quetzalcoatl in the guise of an old man, but was told that he was sick, and was at first
refused entrance. Later, however, he was admitted, Quetzalcoatl observing that he had
waited for him for many days. Tezcatlipocâ then produced a draught of medicine which,
he assured the sick king, would intoxicate him, ease his heart, and carry his thoughts
away from the trials and fatigues of death and departure. 76 This [124]latter phrase
roused Quetzalcoatl to ask where he must go, for that he had a premonition of
departure seems clear. “To Tollantlapallan,” replied Tezcatlipocâ, “where another old
man awaits thee. He and you shall speak together, and on thy return thou shalt be as a
youth, yea as a boy.” With little goodwill Quetzalcoatl quaffed the medicine, and having
once tasted of it he drank more deeply, so that at last he became intoxicated and
maudlin. That which he had drunk was the wine made from the maguey-plant, called
teoncetl (“drink of the gods”). And so great a longing to depart came upon him that at
length he arose and went from Tollan. 77 Ere departing, Quetzalcoatl burned his houses
of shells and silver and buried many precious things in the mountains and ravines. He
turned the cocoa-trees into mezquites and dispatched all the birds of brilliant plumage
in Anahuac, three hundred miles away. On his journey to the coast he came to the hill
Quauhtitlan, where he found a great tree, under which he rested. Gazing into a mirror,
as he reclined under its shade, he said, “I am very old,” named the place
Ueuequauhtitlan after his saying, 78 and stoned the tree. The stones he cast at it sank
into its trunk, and were to be seen remaining there for long afterwards. Preceded by
flute-players, he recommenced his journey, but once more became weary, and rested
on a stone by the wayside. Looking towards Tollan, he wept, and his tears pitted the
stone on which he sat, and the imprints of his hands and thighs also remained thereon.
That place he called Temacpalco. Reaching a great river, he halted until a stone bridge
was built over it, and having crossed, he called the place Tepanaoya. Certain sorcerers
now met him, and asked him whither he was bound, why he had left his city of Tollan,
and who would now do penance there. Quetzalcoatl replied that he must go, that he
was called to Tlapallan by the Sun. The sorcerers requested him to leave behind his
knowledge of the mechanical arts, the smelting of silver, the working [125]of precious
stones, and masonry, painting, and feather-work. These he left with them perforce. But
his treasure of jewels he cast into the fountain of Cozcaapan hard by. Another magician
whom he met insisted upon his drinking a draught which he could give “to none of the
living.” Intoxicated, he slept, and when he awoke, tore his hair. That place was called
Cachtoca. Pursuing his journey, he passed between a mountain of snow and a
volcano, where his hump-backed and dwarfish servants perished from the excessive
cold. Bitterly he bewailed their death in song. Passing on, leaving signs of his progress
on every hand, and sliding down the mountains, he tarried here and there, building a
tlachtli court at one place, the markings of which were visible in deep gashes on the
hills. Once he transfixed a tree with a dart or with another tree, so that it resembled a
cross. In other localities he constructed subterranean houses (mictlan­calco), and
elsewhere balanced a great rolling-stone, and on all these spots he conferred names.
At length he came to the sea-shore, where he commanded that a raft of snakes
(coatapochtli) should be constructed for him. In this he seated himself as in a canoe,
put out to sea, and set out for Tlapallan. 79

Torquemada’s account of the Quetzalcoatl myth somewhat resembles that of Sahagun,


due, no doubt, to the circumstance that he had access to the unpublished MS. of that
author, from which he borrowed in a wholesale manner. The points of difference are
these: Quetzalcoatl was high-priest of Tollan, whence he migrated to Cholula. The ruler
of Tollan was one Huemac, but Quetzalcoatl was its chief in spiritual and ecclesiastical
matters. In drinking the magic potion of Tezcatlipocâ, Quetzalcoatl desired to render
himself immortal. He left the impress of his body on a stone situated on a mountain
near the city of Tlalnepantla (or Temacpalco), two leagues from Mexico, as the natives
declared to Torquemada himself. Met by the sorcerers Tezcatlipocâ and the others who
tried to hinder his going, he refused to stay his progress, and said that he must pass on
to the sun-land. [126]Father Sahagun, remarks Torquemada, when at Xochimilco, was
asked by the natives, who were keenly desirous of knowledge on the point, where
Tlapallan was, and replied that he did not know, as he had then not been long among
them. The fountain in which Quetzalcoatl cast his jewels was now called Coaapan, “in
the snake-water.” He then passed on to Cholula, where he was adored as a god. When
he had resided there for twenty years, he was expelled by Tezcatlipocâ. Setting out
once more for Tlapallan, accompanied by four virtuous youths, he embarked at
Coatzacoalco. Bidding farewell to his disciples, he assured them that at a future time
there would come by way of the sea, where the sun rises, certain white men with white
beards, like him, and that these would be his brothers and would rule the land. These
disciples became the rulers of the four provinces of Cholula. Quetzalcoatl was god of
the air, and during his life on earth was devoted to the careful observance of the older
forms of worship, but instituted many new rites, ceremonies, and festivals and made
the calendar. Barren women prayed to him. He swept the road, so that the Tlaloque
might rain. For a month or so before the rainy season stormy winds blew throughout
New Spain. The Cholulans preserved as relics green stones that had belonged to him,
on one of which was carved a monkey’s head. A great temple to him was founded at
Cholula. 80

Elsewhere Torquemada descants on the Quetzalcoatl myth as follows: A body of men


came from the north by way of Panuco, dressed in long robes of black linen, cut low at
the neck, with short sleeves. They came to Tollan, but finding the country there too
thickly peopled, passed on to Cholula, where they were well received. Their chief was
Quetzalcoatl, a man with ruddy complexion and long beard. These people multiplied
and sent colonists to the Mixtec and Zapotec countries, raising the great buildings at
Mitla. They were cunning handicraftsmen, not so good at masonry as at jewellers’
work, sculpture, and agriculture. Tezcatlipocâ and Huemac conceived an enmity to
Quetzalcoatl, and as [127]he did not wish to go to war with them, he and his folk
removed to Onohualco (Yucatan, Tabasco, and Campeche). 81

Motolinia says of Quetzalcoatl that when Iztacmixcoatl, the Mexican Adam, married his
second wife Chimalmat, she bore him Quetzalcoatl, who grew up chaste and
temperate. He instituted fasting and mortification, and never married. He founded the
custom of drawing blood from the ears and tongue in penitence. A certain
Chichemecatl fastened a leather strap to his arm, near the shoulder, and from that time
this Chichemecatl was known as Acolhuatl, and became the ancestor of the Colhua.
Quetzalcoatl was god of the air and many temples were raised to him. 82

Mendieta has much to say of Quetzalcoatl, but in a synopsis of his account we retain
only such circumstances as have not been already alluded to: Many different traditions
regarding Quetzalcoatl existed, some saying that he was the son of Camacotli
(Camaxtli), god of hunting and fishing, and of his wife Chimialuna; others that
Chimialuna, when sweeping one day, found a chalchihuitl stone, by virtue of which she
became miraculously pregnant and gave birth to Quetzalcoatl, who came either from
Tollan or Yucatan. The people came to love him, not only because he taught them
handicrafts, and desired no offerings but those of bread, flowers, and perfumes. He
forbade all war and disturbance. Pilgrims came to his shrine at Cholula from all parts of
Mexico, even the enemies of Cholula, and the lords of distant lands built them chapels
and idols there. Among all the gods only Quetzalcoatl was called Lord, and men swore
by him. The gods thought it well that the people should have some means of writing by
which they might direct themselves, and two of their number, Oxomoco and Cipactonal,
who dwelt in a cave in Cuernavaca, especially considered the matter. Cipactonal
thought that her descendant Quetzalcoatl should be consulted, and she called him into
counsel. He, too, thought the idea of a calendar good, and the two addressed
themselves to the task of making the tonalamatl. To Cipactonal was given the privilege
of choosing [128]and writing the first sign. She painted the cipactli animal, and called the
sign ce cipactli (“one cipactli”). Oxmoco then wrote ome acatl (“two cane”), and
Quetzalcoatl “three house,” and so on, until the thirteen signs were completed. 83

Another form of the Quetzalcoatl myth given by Mendieta is in substance as follows:


Tezcatlipocâ let himself down from the upper regions by means of a spider’s web, and
coming to Tollan engaged in a game of tlachtli (the native ball game) with Quetzalcoatl,
in the midst of which he transformed himself into a tiger. Those who watched the game
were panic-stricken, and cast themselves pell-mell into a ravine, and were drowned in a
river which flowed therein. Tezcatlipocâ then harassed Quetzalcoatl from city to city,

You might also like